Skip to content
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 used-before-assignmnet for assignment expressions in class initialisers #5212

Closed
DanielNoord opened this issue Oct 26, 2021 · 0 comments · Fixed by #5748
Closed
Labels
Assignment expression Related to the walrus operator / assignment expression C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.8

Comments

@DanielNoord
Copy link
Collaborator

DanielNoord commented Oct 26, 2021

Bug description

Same with classes and dataclasses:

class Dummy:
    def __init__(self, value):
        self.value = value

dummy = Dummy(value=val if (val := 'something') else 'anything')
print(dummy.value)

raises used-before-assigment, while

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.

Originally posted by @egormm in #3688 (comment)

Configuration

No response

Command used

pylint

Pylint output

`used-before-assignment` warning in the first example

Expected behavior

No used-before-assignment errors for the first example.

Pylint version

pylint 2.11.2-dev0
astroid 2.8.4
Python 3.9.6 (default, Aug  2 2021, 08:23:35) 
[Clang 12.0.5 (clang-1205.0.22.11)]

OS / Environment

No response

Additional dependencies

No response

@DanielNoord DanielNoord added python 3.8 False Positive 🦟 A message is emitted but nothing is wrong with the code Assignment expression Related to the walrus operator / assignment expression labels Oct 26, 2021
@cdce8p cdce8p added the C: used-before-assignment Issues related to 'used-before-assignment' check label Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Assignment expression Related to the walrus operator / assignment expression C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.8
Projects
None yet
2 participants