Skip to content

Commit 654d2e3

Browse files
committed
Work around the numpy failures for now
1 parent c119fc8 commit 654d2e3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mypy/applytype.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ParamSpecType,
1919
PartialType,
2020
ProperType,
21+
TupleType,
2122
Type,
2223
TypeAliasType,
2324
TypeVarId,
@@ -27,10 +28,20 @@
2728
UninhabitedType,
2829
UnpackType,
2930
get_proper_type,
31+
get_proper_types,
3032
remove_dups,
3133
)
3234

3335

36+
def _is_tuple_any(typ: ProperType) -> bool:
37+
return (
38+
isinstance(typ, Instance)
39+
and typ.type.fullname == "builtins.tuple"
40+
and len(typ.args) == 1
41+
and isinstance(get_proper_type(typ.args[0]), AnyType)
42+
)
43+
44+
3445
def get_target_type(
3546
tvar: TypeVarLikeType,
3647
type: Type,
@@ -56,6 +67,18 @@ def get_target_type(
5667
# is also a legal value of T.
5768
if all(any(mypy.subtypes.is_same_type(v, v1) for v in values) for v1 in p_type.values):
5869
return type
70+
if _is_tuple_any(p_type) and all(
71+
isinstance(v, TupleType)
72+
or isinstance(v, Instance)
73+
and v.type.fullname == "builtins.tuple"
74+
for v in get_proper_types(values)
75+
):
76+
# tuple[Any, ...] is compatible with any tuple bounds. It is important
77+
# to not select one of the values in cases like numpy arrays shape. Given
78+
# T = TypeVar("T", tuple[()], tuple[int], tuple[int, int])
79+
# and a proposed solution `tuple[Any, ...]`, we do not want to choose
80+
# tuple[()] arbitrarily.
81+
return type
5982
matching = []
6083
for value in values:
6184
if mypy.subtypes.is_subtype(type, value):

0 commit comments

Comments
 (0)