File tree 2 files changed +8
-4
lines changed
2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -48,16 +48,18 @@ def get_dataclass_source(s):
48
48
# %% ../nbs/06_docments.ipynb
49
49
def get_source (s ):
50
50
"Get source code for string, function object or dataclass `s`"
51
- return getsource (s ) if isfunction (s ) or ismethod (s ) else get_dataclass_source (s ) if isdataclass (s ) else s
51
+ if isinstance (s ,str ): return s
52
+ return getsource (s ) if isfunction (s ) or ismethod (s ) else get_dataclass_source (s ) if isdataclass (s ) else None
52
53
53
54
# %% ../nbs/06_docments.ipynb
54
55
def _parses (s ):
55
56
"Parse Python code in string, function object or dataclass `s`"
56
- return parse (dedent (get_source (s )))
57
+ return parse (dedent (get_source (s ) or '' ))
57
58
58
59
def _tokens (s ):
59
60
"Tokenize Python code in string or function object `s`"
60
61
s = get_source (s )
62
+ if not s : return []
61
63
return tokenize (BytesIO (s .encode ('utf-8' )).readline )
62
64
63
65
_clean_re = re .compile (r'^\s*#(.*)\s*$' )
Original file line number Diff line number Diff line change 213
213
" #|export\n " ,
214
214
" def get_source(s):\n " ,
215
215
" \" Get source code for string, function object or dataclass `s`\"\n " ,
216
- " return getsource(s) if isfunction(s) or ismethod(s) else get_dataclass_source(s) if isdataclass(s) else s"
216
+ " if isinstance(s,str): return s\n " ,
217
+ " return getsource(s) if isfunction(s) or ismethod(s) else get_dataclass_source(s) if isdataclass(s) else None"
217
218
]
218
219
},
219
220
{
225
226
" #|export\n " ,
226
227
" def _parses(s):\n " ,
227
228
" \" Parse Python code in string, function object or dataclass `s`\"\n " ,
228
- " return parse(dedent(get_source(s)))\n " ,
229
+ " return parse(dedent(get_source(s) or '' ))\n " ,
229
230
" \n " ,
230
231
" def _tokens(s):\n " ,
231
232
" \" Tokenize Python code in string or function object `s`\"\n " ,
232
233
" s = get_source(s)\n " ,
234
+ " if not s: return []\n " ,
233
235
" return tokenize(BytesIO(s.encode('utf-8')).readline)\n " ,
234
236
" \n " ,
235
237
" _clean_re = re.compile(r'^\\ s*#(.*)\\ s*$')\n " ,
You can’t perform that action at this time.
0 commit comments