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

Incorrect linting with type parameters PEP695 (generic) #9110

Closed
wookayin opened this issue Oct 4, 2023 · 3 comments · Fixed by #9150
Closed

Incorrect linting with type parameters PEP695 (generic) #9110

wookayin opened this issue Oct 4, 2023 · 3 comments · Fixed by #9150
Assignees
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check python 3.12
Milestone

Comments

@wookayin
Copy link

wookayin commented Oct 4, 2023

Bug description

Python 3.12.0

Possibly sharing the same root cause as #9098 but I'm reporting as the behavior is different just in case (here no crashes, just incorrect results). It'd be great if pylint can support all the type parameters specification described in https://peps.python.org/pep-0695/.

def constrained[T: (str, bytes)](argument: T) -> T:
    return argument

(EDIT: removed the second example in edit because it's not valid)

Configuration

No pylintrc is used (under the default setting).

Command used

pylint 695.py --disable=C0114,C0116

(Note: C0114, C0116 are missing docstrings)

Pylint output

************* Module 695
695.py:1:43: E0602: Undefined variable 'T' (undefined-variable)
695.py:1:49: E0602: Undefined variable 'T' (undefined-variable)
695.py:1:16: W0612: Unused variable 'T' (unused-variable)

Expected behavior

There should be no E0602, W0612, E0602 warnings and errors. T in the parameter annotation is the generic type.

Pylint version

pylint 3.0.0
astroid 3.0.0
Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:36:57) [Clang 15.0.7 ]

OS / Environment

macOS and Linux

Additional dependencies

N/A
@wookayin wookayin added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 4, 2023
@DanielNoord
Copy link
Collaborator

@jacobtylerwalls do we have any idea how hard it is to support the new typing syntax for the variables checker?

@jacobtylerwalls
Copy link
Member

I do think it's the same root cause as #9098. Not terribly difficult, just figuring out how to make assigned_stmts() return the correct thing. A few hours? (I'm traveling this week).

@jacobtylerwalls jacobtylerwalls added Astroid Related to astroid and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 4, 2023
@jacobtylerwalls jacobtylerwalls added C: used-before-assignment Issues related to 'used-before-assignment' check python 3.12 labels Oct 12, 2023
@jacobtylerwalls
Copy link
Member

Turns out this is a distinct fix from the crash. The crash can be fixed in astroid; the false positives can be fixed in pylint. Patches coming up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check python 3.12
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants