-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inference
Description
Bug Report
Mypy allows the assignment
it: Iterator[str] = iter(d) where d is dict[int, str].
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=05c55a654acd175b763be1c73567a107
from typing import Iterator
d: dict[int, str] = {1: 'A'}
it: Iterator[str] = iter(d) # mypy does not complain, although iter(d) has type Iterator[int]!
s = next(it) + 'foo' # TypeError: unsupported operand type(s) for +: 'int' and 'str'
Expected Behavior
Mypy raises an error such as
error: Argument 1 to "iter" has incompatible type "dict[int, str]"; expected "SupportsIter[Iterator[str]]"
Actual Behavior
Success: no issues found in 1 source file
Your Environment
mypy Playground
- Mypy version used: mypy latest 1.17.1
- Mypy command-line flags: --strict
- Python version used: 3.12
brianschubert
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inference