Not reporting any error when function returns bool type while expecting str type
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Riproduci la funzione segnalata con mypy 0.782, Python 3.7.7 e le opzioni indicate --strict-equality e --ignore-missing-imports, quindi confronta i diagnostici con l’errore previsto del tipo restituito. Traccia il percorso del controllo dei tipi per le espressioni di ritorno e i tipi sconosciuti; il lavoro è completo quando il comportamento è corretto o chiaramente documentato con un test di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi
I noticed a situation where I wasn't getting a type error from mypy when I would have expected to get one.
Below is the code I have. I purposefully set the return type to str because I wanted to see a mypy error, and specifically I expected the error to be that I had set the wrong return type (e.g. as the code is doing a comparison, which will thus return a bool type, I expected mypy to say the return type should be of type bool):
def is_dev() -> str:
return settings.get("environment") == "dev"
In that code snippet you'll see settings.get(...), which is a function that returns a string, and we compare that string against another string.
Note: as
settings.getis custom code, mypy knows nothing about what type is being returned.
My hypothesis is that because my specific example uses code that mypy can't identify the type for (i.e. settings.get()), mypy just goes ahead and ignores any other possible type check errors (such as me specifying the return type as str).
If that's expected of mypy then fine, but it just confused me.
I'm using mypy version 0.782 and Python version 3.7.7.
I'm running mypy in two places:
- vim integration (e.g.
mypy --ignore-missing-imports --strict-equality) - tox (e.g.
mypy --ignore-missing-imports --package foo)
Note: I've tried also changing to
--no-strict-equalityand it makes no difference.
Thank you for any guidance you can give me.
- 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
- 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.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
bancolombia/sentinel#23 ·
-
test md ApertaCI
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100