Skip to content

Commit e9bb3ec

Browse files
committed
mypy type annotations fix: replace unicode -> Text
1 parent 3080c69 commit e9bb3ec

File tree

7 files changed

+92
-92
lines changed

7 files changed

+92
-92
lines changed

schema_salad/jsonld_context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def pred(datatype, # type: Dict[str, Union[Dict, str]]
3838
# type: (...) -> Union[Dict, Text]
3939
split = urlparse.urlsplit(name)
4040

41-
vee = None # type: Optional[Union[str, unicode]]
41+
vee = None # type: Optional[Union[str, Text]]
4242

4343
if split.scheme != '':
4444
vee = name
@@ -131,7 +131,7 @@ def process_type(t, # type: Dict[str, Any]
131131
_logger.debug("Processing field %s", i)
132132

133133
v = pred(t, i, fieldname, context, defaultPrefix,
134-
namespaces) # type: Union[Dict[Any, Any], unicode, None]
134+
namespaces) # type: Union[Dict[Any, Any], Text, None]
135135

136136
if isinstance(v, six.string_types):
137137
v = v if v[0] != "@" else None
@@ -190,8 +190,8 @@ def salad_to_jsonld_context(j, schema_ctx):
190190
return (context, g)
191191

192192

193-
def fix_jsonld_ids(obj, # type: Union[Dict[unicode, Any], List[Dict[unicode, Any]]]
194-
ids # type: List[unicode]
193+
def fix_jsonld_ids(obj, # type: Union[Dict[Text, Any], List[Dict[Text, Any]]]
194+
ids # type: List[Text]
195195
):
196196
# type: (...) -> None
197197
if isinstance(obj, dict):
@@ -205,8 +205,8 @@ def fix_jsonld_ids(obj, # type: Union[Dict[unicode, Any], List[Dict[unicode,
205205
fix_jsonld_ids(entry, ids)
206206

207207

208-
def makerdf(workflow, # type: Union[str, unicode]
209-
wf, # type: Union[List[Dict[unicode, Any]], Dict[unicode, Any]]
208+
def makerdf(workflow, # type: Union[str, Text]
209+
wf, # type: Union[List[Dict[Text, Any]], Dict[Text, Any]]
210210
ctx, # type: ContextType
211211
graph=None # type: Graph
212212
):

schema_salad/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import pkg_resources # part of setuptools
1212

13-
from typing import Any, Dict, List, Union
13+
from typing import Any, Dict, List, Union, Text
1414

1515
from rdflib import Graph, plugin
1616
from rdflib.serializer import Serializer
@@ -30,8 +30,8 @@
3030

3131

3232
def printrdf(workflow, # type: str
33-
wf, # type: Union[List[Dict[unicode, Any]], Dict[unicode, Any]]
34-
ctx, # type: Dict[unicode, Any]
33+
wf, # type: Union[List[Dict[Text, Any]], Dict[Text, Any]]
34+
ctx, # type: Dict[Text, Any]
3535
sr # type: str
3636
):
3737
# type: (...) -> None

schema_salad/makedoc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def table(self, header, body): # type: (Text, Text) -> Text
5858
) % (header, body)
5959

6060

61-
def to_id(text): # type: (Union[str, unicode]) -> Union[str, unicode]
61+
def to_id(text): # type: (Union[str, Text]) -> Union[str, Text]
6262
textid = text
6363
if text[0] in ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"):
6464
try:
@@ -229,7 +229,7 @@ def typefmt(self,
229229
nbsp=False, # type: bool
230230
jsonldPredicate=None # type: Optional[Dict[str, str]]
231231
):
232-
# type: (...) -> Union[str, unicode]
232+
# type: (...) -> Union[str, Text]
233233
if isinstance(tp, list):
234234
if nbsp and len(tp) <= 3:
235235
return "&nbsp;|&nbsp;".join([self.typefmt(n, redirects, jsonldPredicate=jsonldPredicate) for n in tp])
@@ -419,12 +419,12 @@ def extendsfrom(item, ex):
419419

420420

421421
def avrold_doc(j, outdoc, renderlist, redirects, brand, brandlink, primtype):
422-
# type: (List[Dict[unicode, Any]], IO[Any], str, Dict, str, str, str) -> None
422+
# type: (List[Dict[Text, Any]], IO[Any], str, Dict, str, str, str) -> None
423423
toc = ToC()
424424
toc.start_numbering = False
425425

426426
rt = RenderType(toc, j, renderlist, redirects, primtype)
427-
content = rt.typedoc.getvalue() # type: unicode
427+
content = rt.typedoc.getvalue() # type: Text
428428

429429
outdoc.write("""
430430
<!DOCTYPE html>
@@ -512,7 +512,7 @@ def main(): # type: () -> None
512512

513513
args = parser.parse_args()
514514

515-
s = [] # type: List[Dict[unicode, Any]]
515+
s = [] # type: List[Dict[Text, Any]]
516516
a = args.schema
517517
with open(a) as f:
518518
if a.endswith("md"):

schema_salad/ref_resolver.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ def SubLoader(loader): # type: (Loader) -> Loader
103103
skip_schemas=loader.skip_schemas)
104104

105105
class Fetcher(object):
106-
def fetch_text(self, url): # type: (unicode) -> unicode
106+
def fetch_text(self, url): # type: (Text) -> Text
107107
raise NotImplementedError()
108108

109-
def check_exists(self, url): # type: (unicode) -> bool
109+
def check_exists(self, url): # type: (Text) -> bool
110110
raise NotImplementedError()
111111

112-
def urljoin(self, base_url, url): # type: (unicode, unicode) -> unicode
112+
def urljoin(self, base_url, url): # type: (Text, Text) -> Text
113113
raise NotImplementedError()
114114

115115

@@ -122,7 +122,7 @@ def __init__(self,
122122
self.session = session
123123

124124
def fetch_text(self, url):
125-
# type: (unicode) -> unicode
125+
# type: (Text) -> Text
126126
if url in self.cache:
127127
return self.cache[url]
128128

@@ -152,7 +152,7 @@ def fetch_text(self, url):
152152
else:
153153
raise ValueError('Unsupported scheme in url: %s' % url)
154154

155-
def check_exists(self, url): # type: (unicode) -> bool
155+
def check_exists(self, url): # type: (Text) -> bool
156156
if url in self.cache:
157157
return True
158158

@@ -178,9 +178,9 @@ class Loader(object):
178178
def __init__(self,
179179
ctx, # type: ContextType
180180
schemagraph=None, # type: rdflib.graph.Graph
181-
foreign_properties=None, # type: Set[unicode]
182-
idx=None, # type: Dict[unicode, Union[CommentedMap, CommentedSeq, unicode, None]]
183-
cache=None, # type: Dict[unicode, Any]
181+
foreign_properties=None, # type: Set[Text]
182+
idx=None, # type: Dict[Text, Union[CommentedMap, CommentedSeq, Text, None]]
183+
cache=None, # type: Dict[Text, Any]
184184
session=None, # type: requests.sessions.Session
185185
fetcher_constructor=None, # type: Callable[[Dict[unicode, unicode], requests.sessions.Session], Fetcher]
186186
skip_schemas=None # type: bool
@@ -239,29 +239,29 @@ def __init__(self,
239239
self.fetch_text = self.fetcher.fetch_text
240240
self.check_exists = self.fetcher.check_exists
241241

242-
self.url_fields = set() # type: Set[unicode]
243-
self.scoped_ref_fields = {} # type: Dict[unicode, int]
244-
self.vocab_fields = set() # type: Set[unicode]
245-
self.identifiers = [] # type: List[unicode]
246-
self.identity_links = set() # type: Set[unicode]
247-
self.standalone = None # type: Optional[Set[unicode]]
248-
self.nolinkcheck = set() # type: Set[unicode]
249-
self.vocab = {} # type: Dict[unicode, unicode]
250-
self.rvocab = {} # type: Dict[unicode, unicode]
251-
self.idmap = {} # type: Dict[unicode, Any]
252-
self.mapPredicate = {} # type: Dict[unicode, unicode]
253-
self.type_dsl_fields = set() # type: Set[unicode]
242+
self.url_fields = set() # type: Set[Text]
243+
self.scoped_ref_fields = {} # type: Dict[Text, int]
244+
self.vocab_fields = set() # type: Set[Text]
245+
self.identifiers = [] # type: List[Text]
246+
self.identity_links = set() # type: Set[Text]
247+
self.standalone = None # type: Optional[Set[Text]]
248+
self.nolinkcheck = set() # type: Set[Text]
249+
self.vocab = {} # type: Dict[Text, Text]
250+
self.rvocab = {} # type: Dict[Text, Text]
251+
self.idmap = {} # type: Dict[Text, Any]
252+
self.mapPredicate = {} # type: Dict[Text, Text]
253+
self.type_dsl_fields = set() # type: Set[Text]
254254

255255
self.add_context(ctx)
256256

257257
def expand_url(self,
258-
url, # type: unicode
259-
base_url, # type: unicode
258+
url, # type: Text
259+
base_url, # type: Text
260260
scoped_id=False, # type: bool
261261
vocab_term=False, # type: bool
262262
scoped_ref=None # type: int
263263
):
264-
# type: (...) -> unicode
264+
# type: (...) -> Text
265265
if url in (u"@id", u"@type"):
266266
return url
267267

@@ -298,7 +298,7 @@ def expand_url(self,
298298
else:
299299
return url
300300

301-
def _add_properties(self, s): # type: (unicode) -> None
301+
def _add_properties(self, s): # type: (Text) -> None
302302
for _, _, rng in self.graph.triples((s, RDFS.range, None)):
303303
literal = ((six.text_type(rng).startswith(
304304
u"http://www.w3.org/2001/XMLSchema#") and
@@ -309,11 +309,11 @@ def _add_properties(self, s): # type: (unicode) -> None
309309
self.url_fields.add(six.text_type(s))
310310
self.foreign_properties.add(six.text_type(s))
311311

312-
def add_namespaces(self, ns): # type: (Dict[unicode, unicode]) -> None
312+
def add_namespaces(self, ns): # type: (Dict[Text, Text]) -> None
313313
self.vocab.update(ns)
314314

315315
def add_schemas(self, ns, base_url):
316-
# type: (Union[List[unicode], unicode], unicode) -> None
316+
# type: (Union[List[Text], Text], Text) -> None
317317
if self.skip_schemas:
318318
return
319319
for sch in aslist(ns):
@@ -348,7 +348,7 @@ def add_schemas(self, ns, base_url):
348348
self.idx[six.text_type(s)] = None
349349

350350
def add_context(self, newcontext, baseuri=""):
351-
# type: (ContextType, unicode) -> None
351+
# type: (ContextType, Text) -> None
352352
if bool(self.vocab):
353353
raise validate.ValidationException(
354354
"Refreshing context that already has stuff in it")
@@ -413,17 +413,17 @@ def add_context(self, newcontext, baseuri=""):
413413
_logger.debug("vocab is %s", self.vocab)
414414

415415
def resolve_ref(self,
416-
ref, # type: Union[CommentedMap, CommentedSeq, unicode]
417-
base_url=None, # type: unicode
416+
ref, # type: Union[CommentedMap, CommentedSeq, Text]
417+
base_url=None, # type: Text
418418
checklinks=True # type: bool
419419
):
420-
# type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, unicode, None], Dict[unicode, Any]]
420+
# type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, Text, None], Dict[Text, Any]]
421421

422-
lref = ref # type: Union[CommentedMap, CommentedSeq, unicode, None]
422+
lref = ref # type: Union[CommentedMap, CommentedSeq, Text, None]
423423
obj = None # type: Optional[CommentedMap]
424-
resolved_obj = None # type: Optional[Union[CommentedMap, CommentedSeq, unicode]]
424+
resolved_obj = None # type: Optional[Union[CommentedMap, CommentedSeq, Text]]
425425
inc = False
426-
mixin = None # type: Optional[Dict[unicode, Any]]
426+
mixin = None # type: Optional[Dict[Text, Any]]
427427

428428
if not base_url:
429429
base_url = file_uri(os.getcwd()) + "/"
@@ -581,10 +581,10 @@ def _resolve_idmap(self,
581581
typeDSLregex = re.compile(ur"^([^[?]+)(\[\])?(\?)?$")
582582

583583
def _type_dsl(self,
584-
t, # type: Union[unicode, Dict, List]
584+
t, # type: Union[Text, Dict, List]
585585
lc,
586586
filename):
587-
# type: (...) -> Union[unicode, Dict[unicode, unicode], List[Union[unicode, Dict[unicode, unicode]]]]
587+
# type: (...) -> Union[Text, Dict[Text, Text], List[Union[Text, Dict[Text, Text]]]]
588588

589589
if not isinstance(t, (str, six.text_type)):
590590
return t
@@ -627,7 +627,7 @@ def _resolve_type_dsl(self,
627627
t, datum.lc.data[n], document.lc.filename))
628628
if isinstance(datum2, CommentedSeq):
629629
datum3 = CommentedSeq()
630-
seen = [] # type: List[unicode]
630+
seen = [] # type: List[Text]
631631
for i, item in enumerate(datum2):
632632
if isinstance(item, CommentedSeq):
633633
for j, v in enumerate(item):
@@ -647,7 +647,7 @@ def _resolve_type_dsl(self,
647647
document[d] = datum2
648648

649649
def _resolve_identifier(self, document, loader, base_url):
650-
# type: (CommentedMap, Loader, unicode) -> unicode
650+
# type: (CommentedMap, Loader, Text) -> Text
651651
# Expand identifier field (usually 'id') to resolve scope
652652
for identifer in loader.identifiers:
653653
if identifer in document:
@@ -666,7 +666,7 @@ def _resolve_identifier(self, document, loader, base_url):
666666
return base_url
667667

668668
def _resolve_identity(self, document, loader, base_url):
669-
# type: (Dict[unicode, List[unicode]], Loader, unicode) -> None
669+
# type: (Dict[Text, List[Text]], Loader, Text) -> None
670670
# Resolve scope for identity fields (fields where the value is the
671671
# identity of a standalone node, such as enum symbols)
672672
for identifer in loader.identity_links:
@@ -680,7 +680,7 @@ def _resolve_identity(self, document, loader, base_url):
680680
n]] = document[identifer][n]
681681

682682
def _normalize_fields(self, document, loader):
683-
# type: (Dict[unicode, unicode], Loader) -> None
683+
# type: (Dict[Text, Text], Loader) -> None
684684
# Normalize fields which are prefixed or full URIn to vocabulary terms
685685
for d in document:
686686
d2 = loader.expand_url(d, u"", scoped_id=False, vocab_term=True)
@@ -689,9 +689,9 @@ def _normalize_fields(self, document, loader):
689689
del document[d]
690690

691691
def _resolve_uris(self,
692-
document, # type: Dict[unicode, Union[unicode, List[unicode]]]
692+
document, # type: Dict[Text, Union[Text, List[Text]]]
693693
loader, # type: Loader
694-
base_url # type: unicode
694+
base_url # type: Text
695695
):
696696
# type: (...) -> None
697697
# Resolve remaining URLs based on document base
@@ -714,11 +714,11 @@ def _resolve_uris(self,
714714

715715
def resolve_all(self,
716716
document, # type: Union[CommentedMap, CommentedSeq]
717-
base_url, # type: unicode
718-
file_base=None, # type: unicode
717+
base_url, # type: Text
718+
file_base=None, # type: Text
719719
checklinks=True # type: bool
720720
):
721-
# type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, unicode, None], Dict[unicode, Any]]
721+
# type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, Text, None], Dict[Text, Any]]
722722
loader = self
723723
metadata = CommentedMap() # type: CommentedMap
724724
if file_base is None:
@@ -840,7 +840,7 @@ def resolve_all(self,
840840

841841
return document, metadata
842842

843-
def fetch(self, url, inject_ids=True): # type: (unicode, bool) -> Any
843+
def fetch(self, url, inject_ids=True): # type: (Text, bool) -> Any
844844
if url in self.idx:
845845
return self.idx[url]
846846
try:
@@ -868,7 +868,7 @@ def fetch(self, url, inject_ids=True): # type: (unicode, bool) -> Any
868868
FieldType = TypeVar('FieldType', six.text_type, CommentedSeq, CommentedMap)
869869

870870
def validate_scoped(self, field, link, docid):
871-
# type: (unicode, unicode, unicode) -> unicode
871+
# type: (Text, Text, Text) -> Text
872872
split = urlparse.urlsplit(docid)
873873
sp = split.fragment.split(u"/")
874874
n = self.scoped_ref_fields[field]
@@ -892,7 +892,7 @@ def validate_scoped(self, field, link, docid):
892892
"Field `%s` references unknown identifier `%s`, tried %s" % (field, link, ", ".join(tried)))
893893

894894
def validate_link(self, field, link, docid, all_doc_ids):
895-
# type: (unicode, FieldType, unicode, Dict[Text, Text]) -> FieldType
895+
# type: (Text, FieldType, Text, Dict[Text, Text]) -> FieldType
896896
if field in self.nolinkcheck:
897897
return link
898898
if isinstance(link, (str, six.text_type)):
@@ -939,7 +939,7 @@ def getid(self, d): # type: (Any) -> Optional[Text]
939939
return None
940940

941941
def validate_links(self, document, base_url, all_doc_ids):
942-
# type: (Union[CommentedMap, CommentedSeq, unicode, None], unicode, Dict[Text, Text]) -> None
942+
# type: (Union[CommentedMap, CommentedSeq, Text, None], Text, Dict[Text, Text]) -> None
943943
docid = self.getid(document)
944944
if not docid:
945945
docid = base_url

0 commit comments

Comments
 (0)