False positive Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Note: I wasn't sure what a proper title was for this issue, so I chose one that is specific to the issue at hand. I checked typeshed, it looks like the issue is about mypy, not typeshed. I wouldn't be surprised if an issue already existed for this false positive.
Minimal repro:
assert isinstance(email, EmailMessage)
# Fine
r1 = email.get("List-Id", "")
# Fine
r2 = email.get("List-Id", "") or email.get("List-Unsubscribe", "")
# Fine
r3 = bool(email.get("List-Id", "") or email.get("List-Unsubscribe", ""))
# FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
r4 = bool(
email.get("Auto-Submitted", "") in ("no", "")
or email.get("List-Unsubscribe", "")
)
# FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
r5 = email.get("Auto-Submitted", "") in ("no", "") or email.get(
"List-Unsubscribe", ""
)
Both are false positives.
Typeshed:
_T = TypeVar('_T')
class Message:
...
def get(self, name: str, failobj: _T = ...) -> Union[_HeaderType, _T]: ...
-
What is the actual behavior/output?
Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool" -
What is the behavior/output you expect? No error.
-
What are the versions of mypy and Python you are using? mypy 0.711, Python 3.6.7
Do you see the same issue after installing mypy from Git master? haven't tried it but since 0.711 is fairly recent... -
What are the mypy flags you are using? (For example --strict-optional)
[mypy]
ignore_missing_imports = True
follow_imports = skip
check_untyped_defs = False
strict_equality = True
disallow_incomplete_defs = True
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le repro Python minimal et la signature de Message.get montrée dans typeshed, en utilisant mypy 0.711, Python 3.6.7 et les options mypy indiquées. Comparez les deux faux positifs signalés avec le comportement attendu sans erreur, puis suivez le chemin de vérification des types qui traite l’appel à get et l’expression booléenne.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100