[issue33211] lineno and col_offset are wrong on function definitions with decorators

Ethan Smith report at bugs.python.org
Sat Apr 7 17:29:28 EDT 2018


Ethan Smith <ethan at ethanhs.me> added the comment:

In my PR, I added `def_lineno` and `class_lineno` as fields in the ASDL, instead of attributes (since constructors cannot have attributes, only types can). This means they show up in `ast.dump` which is probably not the desired behavior, as it makes the dumped ast whitespace/line offset sensitive.

Therefore I propose we change the line number of the nodes to be the one of the def/class statement. It seems based on [this commit](https://github.com/python/cpython/commit/09aaa88328a5083469b2682230c7f3c62942afab) that the change was done to fix inspect.getsource (so that it started on the first decorator), but I think it is much more logical for inspect to handle decorated items instead of having the ast lie.

One other option could be for a modified ast to have a decorated node, which holds the decorator list, and the class/function. This has the possible downside of being a not-insignificant change to the ast.

----------

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


More information about the Python-bugs-list mailing list