[issue37971] Wrong trace with multiple decorators (linenumber wrong in frame)

Joran van Apeldoorn report at bugs.python.org
Wed Aug 28 14:32:52 EDT 2019


New submission from Joran van Apeldoorn <git at blubmail.nl>:

When applying multiple decorators to a function, a traceback from the top generator shows the bottom generator instead.
For example

----------------
def printingdec(f):
    raise Exception()
    return f

def dummydec(f):
    return f

@printingdec
@dummydec
def foo():
    pass
----------------

gives
Traceback (most recent call last):
  File "bug.py", line 9, in <module>
    @dummydec
  File "bug.py", line 2, in printingdec
    raise Exception()
Exception

instead of
Traceback (most recent call last):
  File "bug.py", line 8, in <module>
    @printingdec
  File "bug.py", line 2, in printingdec
    raise Exception()
Exception


Digging around with sys._getframe() it seems that the frame's linenumber is set wrong internally, leading to the wrong line being displayed.
The ast does display the correct linenumber.

----------
messages: 350686
nosy: control-k
priority: normal
severity: normal
status: open
title: Wrong trace with multiple decorators (linenumber wrong in frame)
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37971>
_______________________________________


More information about the Python-bugs-list mailing list