Skip to content

Commit c3e483b

Browse files
authored
Optimized code.
1 parent fd82ab3 commit c3e483b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

jsonschema/validators.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def resolve_remote(self, uri):
868868
self.store[uri] = result
869869
return result
870870

871-
def store_subschema(self, schema, last_schema=None, last_url=None):
871+
def store_subschema(self, schema, last_url=None):
872872
"""
873873
Using $id or id with $ref, save subschema to self.store
874874
@@ -878,32 +878,30 @@ def store_subschema(self, schema, last_schema=None, last_url=None):
878878
879879
The referring schema.
880880
881-
last_schema:
882-
883-
The referring upper level schema.
884-
885881
last_url:
886882
887-
Save the last URL.
883+
The last url.
888884
"""
889885
if not isinstance(schema, dict) \
890886
or self.resolution_scope in list_schema:
891887
return
892888

893889
for k in schema.keys():
894890
if k in [u"id", u"$id"] and isinstance(schema[k], str_types):
895-
891+
#Splicing the url in the last id with the url in this id,
892+
#and store last_url at the same time.
896893
last_url = urljoin(last_url, schema[k], allow_fragments=True)
897894
url, fragment = urldefrag(last_url)
898895

899-
if last_schema:
900-
self.store[url] = copy.deepcopy(last_schema)
896+
#Save the schema into self.store[url]
897+
self.store[url] = copy.deepcopy(schema)
901898

899+
#Add fragment element in self.store[url]
902900
if fragment:
903901
self.store[url][fragment] = copy.deepcopy(schema)
904902

905903
if isinstance(schema[k], dict):
906-
self.store_subschema(schema[k], schema, last_url)
904+
self.store_subschema(schema[k], last_url)
907905

908906

909907
def validate(instance, schema, cls=None, *args, **kwargs):

0 commit comments

Comments
 (0)