`_v` can be read and written from the outside of the class so the generic class should be invariant properly.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
*Memo:
- mypy --strict test.py
- mypy 1.19.1
- Python 3.14.0
- Windows 11
v can be read and written from the outside of the class so the generic class is invariant properly as shown below:
class Cls[T]:
v: T = cast(T, 100) # Invariant
cls: Cls[int] = Cls[int]()
# It indicates `Invariant`.
cls1: Cls[float] = cls # Errpr
cls2: Cls[int] = cls # No error
cls3: Cls[bool] = cls # Error
# Read & Write
print(cls.v) # No error
cls.v = 200 # No error
Now, _v can be read and written from the outside of the class but the generic class is covariant improperly as shown below so it should be invariant properly:
*Memo:
- A single leading underscore(_abc) just indicates Internal use so it's not private(Readable & Writable).
class Cls[T]:
_v: T = cast(T, 100) # Covariant
cls: Cls[int] = Cls[int]()
# It indicates `Covariant`.
cls1: Cls[float] = cls # No error
cls2: Cls[int] = cls # No error
cls3: Cls[bool] = cls # Error
# Read & Write
print(cls._v) # No error
cls._v = 200 # No error
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il report di test.py con mypy --strict usando le versioni indicate, mypy 1.19.1 e Python 3.14.0. Traccia il modo in cui mypy inferisce la varianza per le classi generiche con attributi pubblici e attributi con un singolo underscore. Il lavoro è completato quando l’esempio _v viene trattato come invariante, preservando le assegnazioni valide e non valide mostrate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100