When tracing 'call' events, skip lines containing decorators to print actual function name.

Python syntax expects function decorators in a separate line so the all lines starting with '@' can be safely skipped.
This commit is contained in:
Christian Zietz 2019-04-23 16:40:55 +01:00 committed by Ram Rachum
parent ff4e64c457
commit 90951065d3

View file

@ -181,9 +181,16 @@ class Tracer:
### Finished newish and modified variables. ###########################
now_string = datetime_module.datetime.now().time().isoformat()
source_line = get_source_from_frame(frame)[frame.f_lineno - 1]
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]
self.write('{indent}{now_string} {event:9} '
'{frame.f_lineno:4} {source_line}'.format(**locals()))
'{line_no:4} {source_line}'.format(**locals()))
return self.trace