Type variables bound by a generic class make no sense in static or class methods.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the three snippets in the issue and compare the current diagnostics for the normal, static, and class methods. Trace the type-checking entry points for generic class methods and determine how the existing invalid-type diagnostic is reached. Done means static and class methods reject the class-bound type variable while the normal instance method continues to work.
Written by the indexing model from the issue text.
Description
Here's a type variable in a normal method. This works fine:
from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
def f(self) -> None:
x: T
However in a static method this doesn't make sense, since we don't have an instance of A to provide any parameterized type for T:
from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
@staticmethod
def f() -> None:
x: T # Error we don't yet provide: Invalid type "__main__.T"
Nor does this make any sense:
from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
@classmethod
def f(cls) -> None:
x: T # Error we don't yet provide: Invalid type "__main__.T"
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100