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

Undefined variable when using generic type parameters (PEP695) #9193

Closed
Manitary opened this issue Oct 25, 2023 · 2 comments · Fixed by #9195
Closed

Undefined variable when using generic type parameters (PEP695) #9193

Manitary opened this issue Oct 25, 2023 · 2 comments · Fixed by #9195
Labels
C: undefined-variable Issues related to 'undefined-variable' check False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.12
Milestone

Comments

@Manitary
Copy link

Manitary commented Oct 25, 2023

Bug description

The behaviour described in #9110 is still observable with pylint 3.0.2:

def f[T](a: T) -> T: ...

works fine but T is marked as undefined variable

Configuration

No response

Command used

pylint .\mwe.py

Pylint output

************* Module mwe
mwe.py:1:0: C0114: Missing module docstring (missing-module-docstring)
mwe.py:1:0: C0116: Missing function or method docstring (missing-function-docstring)
mwe.py:1:12: E0602: Undefined variable 'T' (undefined-variable)
mwe.py:1:18: E0602: Undefined variable 'T' (undefined-variable)
mwe.py:1:9: W0613: Unused argument 'a' (unused-argument)
mwe.py:1:6: W0612: Unused variable 'T' (unused-variable)

Expected behavior

There should be no E0602, E0602, W0612.

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

OS / Environment

OS: Win32NT (10.0.19045.0)

Additional dependencies

No response

@Manitary Manitary added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 25, 2023
@jacobtylerwalls jacobtylerwalls self-assigned this Oct 28, 2023
@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.12 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 28, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.0.3 milestone Oct 28, 2023
@jacobtylerwalls jacobtylerwalls added C: undefined-variable Issues related to 'undefined-variable' check Needs astroid update Needs an astroid update (probably a release too) before being mergable labels Oct 28, 2023
@jacobtylerwalls jacobtylerwalls removed the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Oct 28, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Feb 25, 2024
    Include PEP 695 (Python 3.12) generic type syntax nodes in get_children(),
    allowing checkers to visit them.
    Refs pylint-dev/pylint#9193
    Add __main__ as a possible inferred value for __name__ to improve
    control flow inference around if __name__ == "__main__": guards.
    Closes #2071
    Following a deprecation period, the names arg to the Import constructor and
    the op arg to the BoolOp constructor are now required, and the doc args
    to the PartialFunction and Property constructors have been removed (call
    postinit(doc_node=...) instead.)
    Following a deprecation announced in astroid 1.5.0, the alias AstroidBuildingException is removed in favor of AstroidBuildingError.
    Include modname in AST warnings. Useful for invalid escape sequence warnings
    with Python 3.12.
    RecursionError is now trapped and logged out as UserWarning during astroid node transformations with instructions about raising the system recursion limit.
    Closes pylint-dev/pylint#8842
    Suppress SyntaxWarning for invalid escape sequences on Python 3.12 when parsing modules.
    Closes pylint-dev/pylint#9322
@inikishev
Copy link

I am still getting this, although for some reason sometimes it is fine and sometimes it shows UndefinedVariable,
Image

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Oct 17, 2024

Could be due to parallélisation that brings worse inférence if you analyse only some of the files (can't link to thé faq in the doc as I'm on mobile, sorry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: undefined-variable Issues related to 'undefined-variable' check False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.12
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants