Ethan Smith <et...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue33211>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to