-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enumerate causes incompatible type mypy error #11934
Comments
You can try this (if you are using from typing import Union
def process(actions: Union[list[str], list[int]]) -> None:
for pos, action in enumerate[str | int](actions):
act(action)
def act(action: Union[str, int]) -> None:
print(action) But, I agree that automatically infering |
This is yet another case where mypy's choice to use join rather than union causes problems. Pyright uses only unions, never joins, so it produces the expected result in this case. Has there been any serious discussion of changing mypy's behavior to use unions instead of joins? I can't think of any case where joins are preferable, and there are many cases where unions are better because they retain more detailed type information. |
CC @JukkaL |
Closing as a duplicate of #8586 |
Bug Report
When using the enumerate function mypy seems to generalise the output to
object
instead of respecting the type of the inputTo Reproduce
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:
Your Environment
The text was updated successfully, but these errors were encountered: