Problem with setting one TypedDict variable to another TypedDict variable
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
- Are you reporting a bug, or opening a feature request?
Bug
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
TestOne = TypedDict('TestOne', {'test': int, 'another': str}, total=False)
TestTwo = TypedDict('TestTwo', {'test': int}, total=False)
var_1: TestOne = {'test': 1, 'another': 'hi'}
var_2: TestTwo = var_1 # Doesn't cause a type error... why not?? 'another' is not a valid key on a TestTwo
var_3: TestTwo = { # Does cause a type error, correctly. "Extra key 'another' for TypedDict 'TestTwo'"
'test': 2, 'another': 'hi'
}
TestThree = TypedDict('TestThree', {'test': int}, total=False)
TestFour = TypedDict('TestFour', {'test': int, 'another': str}, total=False)
var_4: TestThree = {'test': 3}
var_5: TestFour = var_4 # Causes a type error.... WHY???? "Incompatible types in assignment (expression has type "TestThree", variable has type "TestFour")"
- What is the actual behavior/output?
Basically, the code above, including its inline notes, but I'll summarize:
If you assign a value who's type is a TypedDict with some keys and total=False to be the value of a variable who's type is another TypedDict with total=False and a subset of the first TypedDict's keys, it throws an error, but it should not.
If you assign a value who's type is a TypedDict with some keys and total=False to be the value of a variable who's type is another TypedDict with total=False and a superset of the first TypedDict's keys, it does not throw an error, but it should.
- What are the versions of mypy and Python you are using?
Python version 3.6.4
Mypy version 0.670
- Do you see the same issue after installing mypy from Git master?
After installing mypy-0.680+dev.4e0a1583aeb00b248e187054980771f1897a1d31 from github, I get the same exact errors.
- What are the mypy flags you are using? (For example --strict-optional)
Here is my mypy.ini:
[mypy]
plugins = sqlmypy
disallow_untyped_calls = False
disallow_untyped_defs = True
ignore_missing_imports = True
warn_return_any = False
follow_imports = silent
allow_redefinition = True
-
If mypy crashed with a traceback, please paste
It did not.
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 la riproduzione minima di TypedDict presente nell'issue e confronta entrambe le direzioni di assegnazione con gli errori segnalati. Traccia quindi il controllo di compatibilità di TypedDict di mypy a partire dal punto di ingresso dell'analisi delle assegnazioni, poi aggiungi o aggiorna una copertura mirata affinché le assegnazioni di sottoinsiemi e sovrainsiemi con total=False producano i risultati attesi.
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
- Specificata chiaramente
- Idoneità per principianti
- 35/100