33from mypy .messages import callable_name
44from mypy .plugin import MethodSigContext
55from mypy .subtypes import is_subtype
6- from mypy .typeops import get_type_vars , make_simplified_union
6+ from mypy .typeops import get_type_vars
77from mypy .types import CallableType , Instance , ProperType
88from mypy .types import Type as MypyType
9- from mypy .types import TypeVarDef , TypeVarId , TypeVarType , union_items
9+ from mypy .types import (
10+ TypeVarDef ,
11+ TypeVarId ,
12+ TypeVarType ,
13+ UnionType ,
14+ union_items ,
15+ )
1016from typing_extensions import Final , final
1117
1218from classes .contrib .mypy .typeops import type_loader
@@ -69,7 +75,10 @@ def _infer_type_var(
6975 self ._ctx ,
7076 ))
7177
72- instance_type = make_simplified_union (instance_types )
78+ # We use `make_union` instead of `make_simplified_union`
79+ # to show all instance items in the output,
80+ # for example `Union[int, float]` won't be converted into `float`.
81+ instance_type = UnionType .make_union (sorted (instance_types ))
7382 if not is_subtype (passed_type , instance_type ):
7483 # Let's explain: what happens here?
7584 # We need to enforce
@@ -92,9 +101,9 @@ def _infer_regular(self, first_arg: MypyType) -> CallableType:
92101 self ._ctx ,
93102 should_replace_typevars = True ,
94103 )
95- self ._signature .arg_types [0 ] = make_simplified_union (
104+ self ._signature .arg_types [0 ] = UnionType . make_union ( sorted (
96105 list (filter (None , [self ._instance_type , supports_type ])),
97- )
106+ ))
98107 return self ._signature
99108
100109
0 commit comments