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

Regression used-before-assignment with type annotation in conditional #5499

Closed
whonore opened this issue Dec 10, 2021 · 0 comments · Fixed by #5532
Closed

Regression used-before-assignment with type annotation in conditional #5499

whonore opened this issue Dec 10, 2021 · 0 comments · Fixed by #5532
Labels
Bug 🪲 C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@whonore
Copy link

whonore commented Dec 10, 2021

Bug description

import random

class A:
    def f(self) -> None:
        if random.random() < 0.5:
            _x: A = self  # false-positive: used-before-assignment

    def g(self) -> None:
        _x: A = self  # no warning

This is the same issue reported and fixed in #5342 but it still occurs if the assignment is inside a conditional.

Configuration

No response

Command used

pylint test.py

Pylint output

test.py:6:16: E0601: Using variable 'A' before assignment (used-before-assignment)

Expected behavior

No error

Pylint version

pylint 2.12.2
astroid 2.9.0
Python 3.9.6 (default, Aug 16 2021, 15:13:47) 
[GCC 9.3.0]

OS / Environment

No response

Additional dependencies

No response

@whonore whonore added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 10, 2021
whonore added a commit to whonore/Coqtail that referenced this issue Dec 10, 2021
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 11, 2021
@DanielNoord DanielNoord added this to the 2.13.0 milestone Dec 15, 2021
@DanielNoord DanielNoord added the C: used-before-assignment Issues related to 'used-before-assignment' check label Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants