12
12
from .add_dictlist import add_dictlist
13
13
import re
14
14
import argparse
15
- from typing import Any , IO , Union
15
+ from typing import cast , Any , Dict , IO , List , Optional , Set , Text , Union
16
16
17
17
_logger = logging .getLogger ("salad" )
18
18
@@ -35,7 +35,7 @@ def has_types(items): # type: (Any) -> List[basestring]
35
35
return []
36
36
37
37
38
- def linkto (item ):
38
+ def linkto (item ): # type: (Text) -> Text
39
39
_ , frg = urlparse .urldefrag (item )
40
40
return "[%s](#%s)" % (frg , to_id (frg ))
41
41
@@ -46,10 +46,10 @@ def __init__(self): # type: () -> None
46
46
super (mistune .Renderer , self ).__init__ ()
47
47
self .options = {}
48
48
49
- def header (self , text , level , raw = None ):
49
+ def header (self , text , level , raw = None ): # type: (Text, int, Any) -> Text
50
50
return """<h%i id="%s">%s</h%i>""" % (level , to_id (text ), text , level )
51
51
52
- def table (self , header , body ):
52
+ def table (self , header , body ): # type: (Text, Text) -> Text
53
53
return (
54
54
'<table class="table table-striped">\n <thead>%s</thead>\n '
55
55
'<tbody>\n %s</tbody>\n </table>\n '
@@ -136,7 +136,7 @@ def number_headings(toc, maindoc): # type: (ToC, str) -> str
136
136
137
137
if not skip :
138
138
m = re .match (r'^(#+) (.*)' , line )
139
- if m :
139
+ if m is not None :
140
140
num = toc .add_entry (len (m .group (1 )), m .group (2 ))
141
141
line = "%s %s %s" % (m .group (1 ), num , m .group (2 ))
142
142
line = re .sub (r'^(https?://\S+)' , r'[\1](\1)' , line )
@@ -167,7 +167,7 @@ def __init__(self, toc, j, renderlist, redirects):
167
167
self .docAfter = {} # type: Dict[str, List]
168
168
self .rendered = set () # type: Set[str]
169
169
self .redirects = redirects
170
- self .title = None # type: str
170
+ self .title = None # type: Optional[ str]
171
171
172
172
for t in j :
173
173
if "extends" in t :
@@ -224,7 +224,7 @@ def typefmt(self,
224
224
tp , # type: Any
225
225
redirects , # type: Dict[str, str]
226
226
nbsp = False , # type: bool
227
- jsonldPredicate = None # type: Dict[str, str]
227
+ jsonldPredicate = None # type: Optional[ Dict[str, str] ]
228
228
):
229
229
# type: (...) -> Union[str, unicode]
230
230
global primitiveType
@@ -237,7 +237,7 @@ def typefmt(self,
237
237
if tp ["type" ] == "https://w3id.org/cwl/salad#array" :
238
238
ar = "array<%s>" % (self .typefmt (
239
239
tp ["items" ], redirects , nbsp = True ))
240
- if jsonldPredicate and "mapSubject" in jsonldPredicate :
240
+ if jsonldPredicate is not None and "mapSubject" in jsonldPredicate :
241
241
if "mapPredicate" in jsonldPredicate :
242
242
ar += " | map<%s.%s, %s.%s>" % (self .typefmt (tp ["items" ], redirects ),
243
243
jsonldPredicate [
@@ -251,7 +251,7 @@ def typefmt(self,
251
251
self .typefmt (tp ["items" ], redirects ))
252
252
return ar
253
253
if tp ["type" ] in ("https://w3id.org/cwl/salad#record" , "https://w3id.org/cwl/salad#enum" ):
254
- frg = schema .avro_name (tp ["name" ])
254
+ frg = cast ( Text , schema .avro_name (tp ["name" ]) )
255
255
if tp ["name" ] in redirects :
256
256
return """<a href="%s">%s</a>""" % (redirects [tp ["name" ]], frg )
257
257
elif tp ["name" ] in self .typemap :
@@ -267,9 +267,10 @@ def typefmt(self,
267
267
return """<a href="%s">%s</a>""" % (primitiveType , schema .avro_name (str (tp )))
268
268
else :
269
269
_ , frg = urlparse .urldefrag (tp )
270
- if frg :
270
+ if frg is not '' :
271
271
tp = frg
272
272
return """<a href="#%s">%s</a>""" % (to_id (tp ), tp )
273
+ raise Exception ("We should not be here!" )
273
274
274
275
def render_type (self , f , depth ): # type: (Dict[str, Any], int) -> None
275
276
if f ["name" ] in self .rendered or f ["name" ] in self .redirects :
@@ -328,9 +329,11 @@ def extendsfrom(item, ex):
328
329
doc = ""
329
330
330
331
if self .title is None and f ["doc" ]:
331
- self .title = f ["doc" ][0 :f ["doc" ].index ("\n " )]
332
- if self .title .startswith ('# ' ):
333
- self .title = self .title [2 :]
332
+ title = f ["doc" ][0 :f ["doc" ].index ("\n " )]
333
+ if title .startswith ('# ' ):
334
+ self .title = title [2 :]
335
+ else :
336
+ self .title = title
334
337
335
338
if f ["type" ] == "documentation" :
336
339
f ["doc" ] = number_headings (self .toc , f ["doc" ])
0 commit comments