Type variables bound by a generic class make no sense in static or class methods.
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
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"
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Merge moyen
- 1 j 18 h
- PR mergées (30 j)
- 54
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/mypy
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
bug topic-configuration topic-error-reporting
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Toutes les issues de python/mypy
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
zostera/django-bootstrap4#894 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
use-agent-os/agent-os#3276 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
NousResearch/hermes-agent#117848 ·