Skip to content

Processing of Callables in make_simplified_union is order dependent #2031

Description

@ddfisher
fromtypingimportUnion, AnyclassA():
deffoo(self, x: Any) ->None: passclassB():
deffoo(self, x: str) ->None: passdeff(c: Union[A, B]) ->None:
reveal_type(c.foo) # E: Revealed type is 'def (x: Any)'defg(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".

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions