Skip to content

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

@Kakadus

Description

@Kakadus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions