Closed
Description
from typing import Union, Any
class A():
def foo(self, x: Any) -> None: pass
class B():
def foo(self, x: str) -> None: pass
def f(c: Union[A, B]) -> None:
reveal_type(c.foo) # E: Revealed type is 'def (x: Any)'
def g(c: Union[B, A]) -> None:
reveal_type(c.foo) # E: Revealed type is 'def (x: builtins.str)'
Prior to #1989 the order of processing was reversed, which is how this bug was discovered. I think what's going on is that Callable[[Any], None]
is compatible with Callable[[str], None]
and vice-versa, so our "is_subtype
" check is combining them.
One possible resolution is to only combine identical types in make_simplified_union
, not "subtypes".