Allow Annotated to wrap Final and ClassVar
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
Bug Report
The behavior of Annotated has been changed so that it is allowed at runtime to wrap ClassVar and Final. This change helps avoid friction with other users of annotations; see https://bugs.python.org/issue46491 for context. This change has landed in 3.11 and has been backported to 3.9, 3.10, and typing_extensions. mypy should follow suit in allowing the wrapping in order to allow the friction lifting to happen in practice.
To Reproduce
from typing import Annotated, ClassVar, Final
class C:
classvar: Annotated[ClassVar[int], (2, 5)] = 4
const: Annotated[Final[int], "metadata"] = 4
Expected Behavior
The above code should type check.
Actual Behavior
antest/antest.py:4: error: Invalid type: ClassVar nested inside other type
antest/antest.py:5: error: Final can be only used as an outermost qualifier in a variable annotation
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.9
- Operating system and version: Gentoo Linux stable
Additional Context
Corresponding issue for dataclasses (incl InitVar) is at https://bugs.python.org/issue46511
pyright changed at https://github.com/microsoft/pyright/commit/8ce7fa6e0ad883fb17407add955273bbfbe506c5
pytype issue at https://github.com/google/pytype/issues/1110
pyre issue at https://github.com/facebook/pyre-check/issues/577
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 eseguendo il reproducer dell’issue per Annotated, ClassVar e Final con il checker attuale e tracciando la gestione esistente di queste forme di annotazione. Aggiungi una copertura di regressione che dimostri che entrambi gli esempi superano il controllo dei tipi senza errori; il lavoro è completato quando i test passano e le diagnostiche segnalate sono scomparse.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 50/100