bpo-33211: Add def_lineno and class_lineno attributes to FunctionDef and ClassDef #6410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As reported in the bug, a decorated function or class like below will report the first line of the decorator as its line number (so the
FunctionDef.linenowill be 1).This change adds a
def_linenofor functions andclass_linenofor classes. These attributes report the real line numbers of the beginning of the function or class definition. This is especially valuable for linters and tools parsing Python.I wasn't sure where to put something in the docs since the
astdocs are sparse.This isn't quite ready yet, I need to figure out what changes I need to make to the unparser (which I will do tomorrow).
https://bugs.python.org/issue33211