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

possibly-used-before-assignment does not treat assert_never the same when imported from typing_extensions #9780

Closed
Kakadus opened this issue Jul 8, 2024 · 1 comment · Fixed by #9782
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@Kakadus
Copy link

Kakadus commented Jul 8, 2024

Bug description

The following code succeeds in the following environment using python 3.12:


pylint 3.2.5
astroid 3.2.2
Python 3.12.4 (main, Jun  7 2024, 06:33:07) [GCC 14.1.1 20240522]

but fails with python 3.10

pylint 3.2.5
astroid 3.2.2
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
from enum import Enum
from typing import Literal
from typing_extensions import assert_never


class As(Enum):
    A = "A"
    AA = "AA"


a: Literal[As.A, As.AA] = As.A

if a == As.A:
    NUM_AS = 1
elif a == As.AA:
    NUM_AS = 2
else:
    assert_never(a)

print(NUM_AS)

Configuration

No response

Command used

./venv/bin/pylint --disable=all --enable=possibly-used-before-assignment test.py

Pylint output

either nothing (success) or

test.py:20:6: E0606: Possibly using variable 'NUM_AS' before assignment (possibly-used-before-assignment)

Expected behavior

I expect pylint to detect that everything is right and it should not detect any issues.

Also, I expect pylint to behave consistent accross different python version

Pylint version

pylint 3.2.5

OS / Environment

Arch (with python 3.12)
Ubuntu (with python 3.10)

Additional dependencies

No response

@Kakadus Kakadus added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 8, 2024
@jacobtylerwalls
Copy link
Member

Thanks for the report, we forgot to handle typing_extensions

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 9, 2024
@jacobtylerwalls jacobtylerwalls added this to the 3.2.6 milestone Jul 9, 2024
@jacobtylerwalls jacobtylerwalls changed the title possibly-used-before-assignment does not handle Literal types when using python<3.12 possibly-used-before-assignment does not treat assert_never the same when imported from typing_extensions Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants