Fix regression for _is_only_type_assignment#5163
Fix regression for _is_only_type_assignment#5163Pierre-Sassoulas merged 14 commits intopylint-dev:mainfrom
_is_only_type_assignment#5163Conversation
Pull Request Test Coverage Report for Build 1375829491
💛 - Coveralls |
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Maybe 'englobing_scope' ?
3907908 to
3e8c630
Compare
cdce8p
left a comment
There was a problem hiding this comment.
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 #5162
- Decorator with inner function, similar to #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 |
cdce8p
left a comment
There was a problem hiding this comment.
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.
| 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.
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.
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
cdce8p
left a comment
There was a problem hiding this comment.
Looks good! Thanks, @DanielNoord 🚀
Type of Changes
Description
Not sure if
parentis the right name for the variable, but couldn't come up with a better one.This closes #5162