-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotationstopic-literal-types
Description
With the following example:
from typing import Literal
dest: Literal["tata", "tutu"]
for src in "tata", "tutu":
dest = srcI'm getting:
error: Incompatible types in assignment (expression has type "str", variable has type "Literal['http', 'https']")
Trying to dig with reveal_type:
t = "tata", "tutu"
reveal_type(t)
reveal_type(t.__iter__())I get:
test.py:2: note: Revealed type is "Tuple[builtins.str, builtins.str]"
test.py:3: note: Revealed type is "typing.Iterator[builtins.str*]"
So it looks OK, but digging with pdb, in mypy/checker.py:analyze_iterable_item_type(), after calling:
iterator = echk.check_method_call_by_name('__iter__', iterable, [], [], expr)[0]
I see:
iterable == Tuple[Literal['foo']?, Literal['bar']?]
iterator == typing.Iterator[builtins.str*])
I think some information is lost here, should iterator get: typing.Iterator[Literal['foo', 'bar']] instead?
chrisyeh96 and xmatthias
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotationstopic-literal-types