Type variables bound by a generic class make no sense in static or class methods.

Aperta
#3,172 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

priority-2-low topic-type-variables

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"
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.