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 T using generic on Class (PEP695) #9335

Open
trentontrees opened this issue Dec 29, 2023 · 6 comments
Open

Undefined variable T using generic on Class (PEP695) #9335

trentontrees opened this issue Dec 29, 2023 · 6 comments
Labels
C: undefined-variable Issues related to 'undefined-variable' check 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 python 3.12

Comments

@trentontrees
Copy link

Bug description

# pylint: disable=missing-module-docstring
class Simple[T]:
  def __init__(self, value: T):
    self.value = value

Configuration

No response

Command used

python3.12 -m pylint a.py

Pylint output

************* Module a
a.py:3:28: E0602: Undefined variable 'T' (undefined-variable)

Expected behavior

There should be no error E0602 reported.

Pylint version

pylint 3.0.3
astroid 3.0.2
Python 3.12.1 (main, Dec  7 2023, 20:45:44) [Clang 15.0.0 (clang-1500.0.40.1)]

OS / Environment

OSX - Sonoma 14.1.2 (23B92)

Additional dependencies

No response

@trentontrees trentontrees added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Dec 29, 2023
@jacobtylerwalls
Copy link
Member

Thanks for the report.

Test case as a diff:

diff --git a/tests/functional/u/undefined/undefined_variable_py312.py b/tests/functional/u/undefined/undefined_variable_py312.py
index 0ca2475eb..88a542653 100644
--- a/tests/functional/u/undefined/undefined_variable_py312.py
+++ b/tests/functional/u/undefined/undefined_variable_py312.py
@@ -4,4 +4,5 @@ def f[T](a: T) -> T:
     print(a)
 
 class ChildClass[T, *Ts, **P]:
-    ...
+    def __init__(self, value: T):
+        self.value = value

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code C: undefined-variable Issues related to 'undefined-variable' check Needs PR This issue is accepted, sufficiently specified and now needs an implementation python 3.12 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 30, 2023
@winstxnhdw
Copy link
Contributor

winstxnhdw commented Mar 19, 2024

I am getting the following error for generics on functions.

Unused variable 'T' Pylint(W0612:unused-variable)

I am on pylint 3.1.0

@e-hart
Copy link

e-hart commented Apr 3, 2024

Same issue here.

Pylint Version

pylint 3.1.0
astroid 3.1.0
Python 3.12.0  [Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

macOS Big Sur 11.7.8 (20G1351)

@lord-haffi
Copy link

Don't know if it's related to this one, but I'm getting the same error with

class A[T]:
    pass

class B[T](A[T]):
    pass

It throws E0602: Undefined variable 'T' (undefined-variable) (only) in line class B[T](A[T]):.

pylint 3.2.6
astroid 3.2.4
Python 3.12.1

@Chris3606
Copy link

Same with the following class:

class MyClass[T]:
    def func(self, x: T, y: T):
        print(x, y)

Version info:

pylint 3.2.6
astroid 3.2.4
Python 3.12.5 

@manuel-gallina
Copy link

Same issue with

pylint 3.3.1
astroid 3.3.5
Python 3.12.5

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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation python 3.12
Projects
None yet
Development

No branches or pull requests

7 participants