summaryrefslogtreecommitdiff
path: root/jsonschema/_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'jsonschema/_utils.py')
-rw-r--r--jsonschema/_utils.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py
index f9fdd2c..47a1b32 100644
--- a/jsonschema/_utils.py
+++ b/jsonschema/_utils.py
@@ -71,22 +71,26 @@ def load_vocabulary(name):
return vocabulary
-def format_as_index(indices):
+def format_as_index(container, indices):
"""
Construct a single string containing indexing operations for the indices.
- For example, [1, 2, "foo"] -> [1][2]["foo"]
+ For example for a container ``bar``, [1, 2, "foo"] -> bar[1][2]["foo"]
Arguments:
+ container (str):
+
+ A word to use for the thing being indexed
+
indices (sequence):
The indices to format.
"""
if not indices:
- return ""
- return f"[{']['.join(repr(index) for index in indices)}]"
+ return container
+ return f"{container}[{']['.join(repr(index) for index in indices)}]"
def find_additional_properties(instance, schema):