-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False positive for undefined variable with assignment expression #3688
Comments
Here's another case. Interestingly, x = next(i for i in range(10) if (y := i * i))
print(y) raises this false-positive, while next(i for i in range(10) if (y := i * i))
print(y) does not. |
A couple more interesting cases with false-positive behaviour: print({'key': value if (value := 'something') else 'anything'}) raises value = val if (val := 'something') else 'anything'
print({'key': value}) doesn't. Excepting behaviour - no errors. class Dummy:
def __init__(self, value):
self.value = value
dummy = Dummy(value=val if (val := 'something') else 'anything')
print(dummy.value) raises class Dummy:
def __init__(self, value):
self.value = value
value = val if (val := 'something') else 'anything'
dummy = Dummy(value)
print(dummy.value) doesn't. Excepting behaviour - no errors. |
* Add tests for assignment expressions in function defaults Ref #3688 * Upgrade astroid to 2.8.4 Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
If have created a new issue for the last two issues of @egormm's comments, as they are related to a different message. |
@Pierre-Sassoulas @DanielNoord I don't think #5213 fixes the original case mentioned here (use of walrus in function default), should this issue be re-opened? |
It should be fixed with #5188. I separated this issue in two PR's as they covered different cases. |
Awesome, missed that, thank you so much!! |
Steps to reproduce
Current behavior
Expected behavior
pylint recognises that
the
is defined. (Or alternatively, pylint yells at me for doing this weird thing in the first place ;-) )pylint --version output
Pretty minor, especially given that assignment expressions aren't a priority for pylint (#3275 (comment)).
The text was updated successfully, but these errors were encountered: