mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 18:24:44 +00:00
Be safe and check that a function definition is found
This commit is contained in:
parent
5e74a351f9
commit
45db942375
1 changed files with 7 additions and 0 deletions
|
|
@ -183,12 +183,19 @@ class Tracer:
|
|||
now_string = datetime_module.datetime.now().time().isoformat()
|
||||
line_no = frame.f_lineno
|
||||
source_line = get_source_from_frame(frame)[line_no - 1]
|
||||
|
||||
if event == 'call':
|
||||
# Skip lines containing function decorators to print actual
|
||||
# function name
|
||||
while source_line.lstrip()[0] == '@':
|
||||
line_no += 1
|
||||
source_line = get_source_from_frame(frame)[line_no - 1]
|
||||
# Check that source_line is actually a function definition,
|
||||
# otherwise fall back to original line
|
||||
if not source_line.lstrip().startswith('def'):
|
||||
line_no = frame.f_lineno
|
||||
source_line = get_source_from_frame(frame)[line_no - 1]
|
||||
|
||||
self.write('{indent}{now_string} {event:9} '
|
||||
'{line_no:4} {source_line}'.format(**locals()))
|
||||
return self.trace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue