Skip to content

Commit 4350b30

Browse files
committed
type clarification
1 parent 96f08e8 commit 4350b30

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

schema_salad/ref_resolver.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, ctx, schemagraph=None, foreign_properties=None,
106106
self.rvocab = {} # type: Dict[unicode, Any]
107107
self.idmap = None # type: Dict[unicode, Any]
108108
self.mapPredicate = None # type: Dict[unicode, unicode]
109-
self.type_dsl_fields = None # type: Set[str]
109+
self.type_dsl_fields = None # type: Set[str]
110110

111111
self.add_context(ctx)
112112

@@ -359,36 +359,37 @@ def _resolve_idmap(self, document, loader):
359359
ls.append(v)
360360
document[idmapField] = ls
361361

362-
typeDSLregex = re.compile(r"^([^[?]+)(\[\])?(\?)?$")
362+
typeDSLregex = re.compile(ur"^([^[?]+)(\[\])?(\?)?$")
363363

364364
def _type_dsl(self, t):
365-
# type: (Any) -> Any
366-
r = t
365+
# type: (Union[unicode, Dict, List]) -> Union[unicode, Dict[unicode, unicode], List[Union[unicode, Dict[unicode, unicode]]]]
367366
if not isinstance(t, (str, unicode)):
368367
return t
369368

370369
m = Loader.typeDSLregex.match(t)
371370
if not m:
372371
return t
373-
r = m.group(1)
372+
first = m.group(1)
373+
second = third = None
374374
if m.group(2):
375-
r = {"type": "array",
376-
"items": r}
375+
second = {u"type": u"array",
376+
u"items": first}
377377
if m.group(3):
378-
r = ["null", r]
379-
return r
378+
third = [u"null", second or first]
379+
return third or second or first
380380

381381
def _resolve_type_dsl(self, document, loader):
382-
# type: (Dict[unicode, Union[unicode, List[unicode]]], Loader) -> None
382+
# type: (Dict[unicode, Union[unicode, Dict[unicode, unicode], List]], Loader) -> None
383383
for d in loader.type_dsl_fields:
384384
if d in document:
385-
if isinstance(document[d], (str, unicode)):
386-
document[d] = self._type_dsl(document[d])
387-
elif isinstance(document[d], list):
388-
document[d] = [self._type_dsl(t) for t in document[d]]
389-
390-
if isinstance(document[d], list):
391-
document[d] = flatten(document[d])
385+
datum = document[d]
386+
if isinstance(datum, (str, unicode)):
387+
document[d] = self._type_dsl(datum)
388+
elif isinstance(datum, list):
389+
document[d] = [self._type_dsl(t) for t in datum]
390+
datum2 = document[d]
391+
if isinstance(datum2, list):
392+
document[d] = flatten(datum2)
392393
seen = [] # type: List[unicode]
393394
uniq = []
394395
for item in document[d]:

0 commit comments

Comments
 (0)