Skip to content

Commit 85abb1c

Browse files
committed
Fixes union order
1 parent 8b3cd4c commit 85abb1c

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

classes/contrib/mypy/typeops/call_signatures.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
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
6+
from mypy.typeops import get_type_vars, make_simplified_union
77
from mypy.types import CallableType, Instance, ProperType
88
from mypy.types import Type as MypyType
9-
from mypy.types import (
10-
TypeVarDef,
11-
TypeVarId,
12-
TypeVarType,
13-
UnionType,
14-
union_items,
15-
)
9+
from mypy.types import TypeVarDef, TypeVarId, TypeVarType, union_items
1610
from typing_extensions import Final, final
1711

1812
from classes.contrib.mypy.typeops import type_loader
@@ -75,10 +69,7 @@ def _infer_type_var(
7569
self._ctx,
7670
))
7771

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))
72+
instance_type = make_simplified_union(instance_types)
8273
if not is_subtype(passed_type, instance_type):
8374
# Let's explain: what happens here?
8475
# We need to enforce
@@ -101,9 +92,9 @@ def _infer_regular(self, first_arg: MypyType) -> CallableType:
10192
self._ctx,
10293
should_replace_typevars=True,
10394
)
104-
self._signature.arg_types[0] = UnionType.make_union(sorted(
95+
self._signature.arg_types[0] = make_simplified_union(
10596
list(filter(None, [self._instance_type, supports_type])),
106-
))
97+
)
10798
return self._signature
10899

109100

classes/contrib/mypy/typeops/instance_args.py

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

33
from mypy.plugin import FunctionContext, MethodContext
4+
from mypy.typeops import make_simplified_union
45
from mypy.types import AnyType, Instance, LiteralType, TupleType
56
from mypy.types import Type as MypyType
67
from mypy.types import TypeVarType, UnboundType, UninhabitedType
@@ -24,14 +25,14 @@ def add_unique(
2425
2526
It is smart: filters our junk and uses unique and flat ``Union`` types.
2627
"""
27-
unified = list(set(filter(
28+
unified = list(filter(
2829
# We filter our `NoReturn` and other things like `Any`
2930
# that can break our instances union.
3031
# TODO: maybe use `has_uninhabited_component`?
3132
lambda type_: not isinstance(type_, _TYPES_TO_FILTER_OUT),
3233
[new_instance_type, existing_instance_type],
33-
)))
34-
return UnionType.make_union(sorted(unified))
34+
))
35+
return make_simplified_union(unified)
3536

3637

3738
def mutate_typeclass_def(

0 commit comments

Comments
 (0)