Skip to content

Commit 8b3cd4c

Browse files
committed
Fixes union order
1 parent 8ec90d6 commit 8b3cd4c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

classes/contrib/mypy/typeops/call_signatures.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
from mypy.messages import callable_name
44
from mypy.plugin import MethodSigContext
55
from mypy.subtypes import is_subtype
6-
from mypy.typeops import get_type_vars, make_simplified_union
6+
from mypy.typeops import get_type_vars
77
from mypy.types import CallableType, Instance, ProperType
88
from 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+
)
1016
from typing_extensions import Final, final
1117

1218
from 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

classes/contrib/mypy/typeops/instance_args.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import List, Union
22

33
from mypy.plugin import FunctionContext, MethodContext
4-
from mypy.typeops import make_simplified_union
54
from mypy.types import AnyType, Instance, LiteralType, TupleType
65
from mypy.types import Type as MypyType
76
from mypy.types import TypeVarType, UnboundType, UninhabitedType
@@ -32,7 +31,7 @@ def add_unique(
3231
lambda type_: not isinstance(type_, _TYPES_TO_FILTER_OUT),
3332
[new_instance_type, existing_instance_type],
3433
)))
35-
return make_simplified_union(unified)
34+
return UnionType.make_union(sorted(unified))
3635

3736

3837
def mutate_typeclass_def(

0 commit comments

Comments
 (0)