enumerate(Union[Sequence, Sequence])
Open
Nobody has claimed this yet.
feature
needs discussion
topic-join-v-union
topic-type-variables
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
- Are you reporting a bug, or opening a feature request?
Bug - Please insert below the code you are checking with mypy.
from typing import Sequence, Union
def baz(idx: int, arg: Union[int, str]) -> None:
pass
def foo(the_list: Union[Sequence[int], Sequence[str]]) -> None:
for idx, val in enumerate(the_list):
reveal_type(idx)
reveal_type(val)
baz(idx, val)
- What is the actual behavior/output?
foo.py:8: note: Revealed type is 'builtins.int'
foo.py:9: note: Revealed type is 'builtins.object*'
foo.py:10: error: Argument 2 to "baz" has incompatible type "object"; expected "Union[int, str]"
- What is the behavior/output you expect?
foo.py:8: note: Revealed type is 'builtins.int'
foo.py:9: note: Revealed type is 'Union[int, str]'
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
0.761, 0.770 and master all have the same result. - What are the mypy flags you are using? (For example --strict-optional)
--strict
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
Reproduce the example in foo.py with mypy and the reported --strict flags, then inspect the type inference path for enumerate over a union of sequences. Done means reveal_type(val) reports Union[int, str] and the call to baz is accepted without weakening unrelated checks.
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