-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions
Description
Bug Report
When using the enumerate function mypy seems to generalise the output to object
instead of respecting the type of the input
To Reproduce
from typing import Union
def process(actions: Union[list[str], list[int]]) -> None:
for pos, action in enumerate(actions):
act(action)
def act(action: Union[str, int]) -> None:
print(action)
Expected Behavior
Mypy raises no errors
Actual Behavior
Mypy raises the following error: Argument 1 to "act" has incompatible type "object"; expected "Union[str, int]"
Its worth noting that the same code without using enumerate does not raise this error:
from typing import Union
def process(actions: Union[list[str], list[int]]) -> None:
for action in actions:
act(action)
def act(action: Union[str, int]) -> None:
print(action)
Your Environment
- Mypy version used: 0.921
- Python version used: 0.9
MarcoGorelli, bl-ue, marcin-szymanski and JakubKahovec
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions