-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix regression for _is_only_type_assignment
#5163
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 regression for _is_only_type_assignment
#5163
Conversation
Pull Request Test Coverage Report for Build 1375829491
π - Coveralls |
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.
Maybe 'englobing_scope' ?
3907908
to
3e8c630
Compare
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 like the test case you've added with global.
Would you mind adding two more, both with and without error?
- Comprehension inside a function, similar to Crash in
VariablesChecker._is_only_type_assignment
Β #5162 - Decorator with inner function, similar to Fix regression for
_is_only_type_assignment
Β #5163 (comment)
--
Lastly, I needed some time to come up this that but assignment expressions aren't covered yet. Maybe that would be better in a new PR though.
def func():
var: int
if (var := var ** 2):
print(var)
I have opened #5197 to track this. We need control-flow for this, as we currently can't recognise whether a Edit: Oops, forgot to separate the assignment expressions tests into a |
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.
Thanks for opening the issue. That's definitely not something we can fix at the moment.
Left some comments. One more thing: I noticed that you used nodes.Statement
as type annotation for defstmt
. Technically this might be correct, but currently it would be an error as it's only recognized as NodeNG
. We need to work on the astroid type annotations some more to fix that.
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
pylint/checkers/variables.py
Outdated
def _is_only_type_assignment( | ||
node: nodes.Name, defstmt: Union[nodes.Module, nodes.Statement] | ||
) -> bool: |
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.
def _is_only_type_assignment( | |
node: nodes.Name, defstmt: Union[nodes.Module, nodes.Statement] | |
) -> bool: | |
def _is_only_type_assignment(node: nodes.Name, defstmt: nodes.NodeNG) -> bool: |
I would suggest we use NodeNG
for now. Can always update that later. That way we can merge this sooner.
Haven't looked at pylint-dev/astroid#1217 yet, but I feel like this should never be Module
in the first place.
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.
Should I then add a TODO that links to the astroid
issue? I fear we might forget about this in the future if we don't make some comment about it now.
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 guess that would work π€·π»ββοΈ
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
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.
Looks good! Thanks, @DanielNoord π
Type of Changes
Description
Not sure if
parent
is the right name for the variable, but couldn't come up with a better one.This closes #5162