False positive Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Python repro and the shown typeshed Message.get signature, using mypy 0.711, Python 3.6.7, and the listed mypy flags. Compare the two reported false positives with the expected no-error behavior, then trace the type-checking path that handles the get call and boolean expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100