-
-
Notifications
You must be signed in to change notification settings - Fork 294
Fix ClassDef.fromlineno
for Python < 3.8
#1395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ClassDef.fromlineno
for Python < 3.8
#1395
Conversation
ClassDef.fromlineno
with Python 3.7ClassDef.fromlineno
for Python < 3.8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
tests/unittest_builder.py
Outdated
|
||
ast_module: nodes.Module = builder.parse(code) # type: ignore[assignment] | ||
|
||
# XXX discussable, but that's what is expected by pylint right now, similar to FunctionDef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say we can remove the discussable
here? Python 3.8+ has clearly made a choice and I think we have made a choice in pylint
as well.
I think this "discussion" has been solved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌🏻 Yeah, for ClassDef
I think it is resolved. Although to be fair, pylint was fine with either option.
I'll leave the comment for FunctionDef.fromlineno
in place though, since this still differs from the stdlib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my personal understanding:
Why don't we set lineno
on a ClassDef
to the value returned by fromlineno
? Is there a difference between the two?
Usually, it's the other way round. We could think about patching the -- Update |
Can a case be made that
Ah you already tested this. Are they failing by not giving the right messages or just requiring an updating of the position? |
Don't know about that. Just my opinion, but I do appreciate knowing that Unless there is a strong reason, I would suggest to just leave it. We have may other areas to deal with.
Not the right message if I remember correctly. Although I haven't checked how much work it would actual be to update the code. |
Description
Another unexpected AST change. For Python < 3.8 the
lineno
forClassDef
nodes also includes decorator nodes. @DanielNoord noticed that one while working withbuilder.extract_node
in #1391. I encountered the same issue in #1393.The fix isn't perfect unfortunately. Multiline decorators without dedicated AST nodes on the last line don't quite work. That however is consistent with
FunctionDef.fromlineno
which has already been modified.--
The current property for
FunctionDef
:https://github.com/PyCQA/astroid/blob/552f1c19aab0719e7b30bb02e032d4bfe655f343/astroid/nodes/scoped_nodes/scoped_nodes.py#L1708-L1722
Type of Changes