Skip to content

Conversation

@emmatyping
Copy link
Member

@emmatyping emmatyping commented Apr 7, 2018

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.lineno will be 1).

@decorate(
        "multi",
        "line"
        )
def foo(
        a,
        b,
        ):
        pass

This change adds a def_lineno for functions and class_lineno for 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 ast docs 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

Decorated functions and classes report the line of the first decorator
as their lineno. This can be misleading and confusing, especially if the
decorator spans multiple lines.
@emmatyping
Copy link
Member Author

I'm abandoning this in favor of a better solution.

@emmatyping emmatyping closed this Apr 12, 2018
@emmatyping emmatyping deleted the decorlineno branch April 12, 2018 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants