-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normaltopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions
Description
Repro:
bug.py:
from __future__ import annotations
from typing import *
class B:
pass
class A:
name: Optional[Union[str, B]]
def foo(a: A):
if isinstance(a.name, str):
pass
elif isinstance(a.name, B):
pass
else:
raise AssertionError
bar(a.name)
def bar(arg: Union[str, B]):
passmypy incorrectly reports an error:
bug.py:22: error: Argument 1 to "bar" has incompatible type "object"; expected "Union[str, B]"
Interestingly, when a.name is aliased with another name, the issue disappers, i.e. the following is checked without an issue:
ok.py:
from __future__ import annotations
from typing import *
class B:
pass
class A:
name: Optional[Union[str, B]]
def foo(a: A):
a_name = a.name
if isinstance(a_name, str):
pass
elif isinstance(a_name, B):
pass
else:
raise AssertionError
bar(a_name)
def bar(arg: Union[str, B]):
passambv and 1st1
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normaltopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions