False Positive when TypedDict instance used as base __map for new instances?
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
Why doesn't mypy accept another TypedDict as the __map argument when defining a new instance as shown below? It seems perfectly valid to me, but I could be missing something.
To Reproduce
Save the following as test_mypy.py and ask mypy to check it:
from typing import TypedDict
class MyTypedDict(TypedDict):
attr1: str
attr2: str
attr3: str
MY_BASE_DICT = MyTypedDict(
attr1="testing",
attr2="typeddict",
attr3="inheritance",
)
new_typed_dict = MyTypedDict(MY_BASE_DICT, attr1="failing")
assert " ".join(new_typed_dict.values()) == "failing typeddict inheritance"
Expected Behavior
> mypy test_mypy.py
Success: no issues found in 1 source file
Actual Behavior
> mypy test_mypy.py
test_mypy.py:17: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor [misc]
Found 1 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: v1.8.0 (command line call) and v1.6.1 (integrated vscode extension)
- Mypy command-line flags: none required although I'm typically adding
--check-untyped-defs --implicit-optional - Mypy configuration options from
mypy.ini(and other config files): n/a - Python version used: 3.10.6
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
Riproduci il problema salvando l’esempio come test_mypy.py ed eseguendo mypy test_mypy.py. Traccia il controllo del costruttore di TypedDict che rifiuta MY_BASE_DICT, quindi aggiungi un test di regressione per usare un’istanza di TypedDict come mappatura di base mantenendo al contempo le sovrascritture tramite keyword. Il lavoro è completato quando l’esempio passa senza l’errore [misc].
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100