Skip to content

Commit ea2fd10

Browse files
authored
Revert "Properly use proper subtyping for callables (python#16343)"
This reverts commit 5c6ca5c.
1 parent 9011ca8 commit ea2fd10

File tree

5 files changed

+9
-51
lines changed

5 files changed

+9
-51
lines changed

mypy/checker.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
800800

801801
# Is the overload alternative's arguments subtypes of the implementation's?
802802
if not is_callable_compatible(
803-
impl, sig1, is_compat=is_subtype, is_proper_subtype=False, ignore_return=True
803+
impl, sig1, is_compat=is_subtype, ignore_return=True
804804
):
805805
self.msg.overloaded_signatures_arg_specific(i + 1, defn.impl)
806806

@@ -7685,7 +7685,6 @@ def is_unsafe_overlapping_overload_signatures(
76857685
signature,
76867686
other,
76877687
is_compat=is_overlapping_types_no_promote_no_uninhabited_no_none,
7688-
is_proper_subtype=False,
76897688
is_compat_return=lambda l, r: not is_subtype_no_promote(l, r),
76907689
ignore_return=False,
76917690
check_args_covariantly=True,
@@ -7695,7 +7694,6 @@ def is_unsafe_overlapping_overload_signatures(
76957694
other,
76967695
signature,
76977696
is_compat=is_overlapping_types_no_promote_no_uninhabited_no_none,
7698-
is_proper_subtype=False,
76997697
is_compat_return=lambda l, r: not is_subtype_no_promote(r, l),
77007698
ignore_return=False,
77017699
check_args_covariantly=False,
@@ -7746,7 +7744,7 @@ def overload_can_never_match(signature: CallableType, other: CallableType) -> bo
77467744
signature, {tvar.id: erase_def_to_union_or_bound(tvar) for tvar in signature.variables}
77477745
)
77487746
return is_callable_compatible(
7749-
exp_signature, other, is_compat=is_more_precise, is_proper_subtype=True, ignore_return=True
7747+
exp_signature, other, is_compat=is_more_precise, ignore_return=True
77507748
)
77517749

77527750

@@ -7756,9 +7754,7 @@ def is_more_general_arg_prefix(t: FunctionLike, s: FunctionLike) -> bool:
77567754
# general than one with fewer items (or just one item)?
77577755
if isinstance(t, CallableType):
77587756
if isinstance(s, CallableType):
7759-
return is_callable_compatible(
7760-
t, s, is_compat=is_proper_subtype, is_proper_subtype=True, ignore_return=True
7761-
)
7757+
return is_callable_compatible(t, s, is_compat=is_proper_subtype, ignore_return=True)
77627758
elif isinstance(t, FunctionLike):
77637759
if isinstance(s, FunctionLike):
77647760
if len(t.items) == len(s.items):
@@ -7773,7 +7769,6 @@ def is_same_arg_prefix(t: CallableType, s: CallableType) -> bool:
77737769
t,
77747770
s,
77757771
is_compat=is_same_type,
7776-
is_proper_subtype=True,
77777772
ignore_return=True,
77787773
check_args_covariantly=True,
77797774
ignore_pos_arg_names=True,

mypy/constraints.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,11 +1352,7 @@ def find_matching_overload_item(overloaded: Overloaded, template: CallableType)
13521352
# Return type may be indeterminate in the template, so ignore it when performing a
13531353
# subtype check.
13541354
if mypy.subtypes.is_callable_compatible(
1355-
item,
1356-
template,
1357-
is_compat=mypy.subtypes.is_subtype,
1358-
is_proper_subtype=False,
1359-
ignore_return=True,
1355+
item, template, is_compat=mypy.subtypes.is_subtype, ignore_return=True
13601356
):
13611357
return item
13621358
# Fall back to the first item if we can't find a match. This is totally arbitrary --
@@ -1374,11 +1370,7 @@ def find_matching_overload_items(
13741370
# Return type may be indeterminate in the template, so ignore it when performing a
13751371
# subtype check.
13761372
if mypy.subtypes.is_callable_compatible(
1377-
item,
1378-
template,
1379-
is_compat=mypy.subtypes.is_subtype,
1380-
is_proper_subtype=False,
1381-
ignore_return=True,
1373+
item, template, is_compat=mypy.subtypes.is_subtype, ignore_return=True
13821374
):
13831375
res.append(item)
13841376
if not res:

mypy/meet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
462462
left,
463463
right,
464464
is_compat=_is_overlapping_types,
465-
is_proper_subtype=False,
466465
ignore_pos_arg_names=True,
467466
allow_partial_overlap=True,
468467
)

mypy/subtypes.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,6 @@ def visit_parameters(self, left: Parameters) -> bool:
658658
left,
659659
self.right,
660660
is_compat=self._is_subtype,
661-
# TODO: this should pass the current value, but then couple tests fail.
662-
is_proper_subtype=False,
663661
ignore_pos_arg_names=self.subtype_context.ignore_pos_arg_names,
664662
)
665663
else:
@@ -679,7 +677,6 @@ def visit_callable_type(self, left: CallableType) -> bool:
679677
left,
680678
right,
681679
is_compat=self._is_subtype,
682-
is_proper_subtype=self.proper_subtype,
683680
ignore_pos_arg_names=self.subtype_context.ignore_pos_arg_names,
684681
strict_concatenate=(self.options.extra_checks or self.options.strict_concatenate)
685682
if self.options
@@ -935,7 +932,6 @@ def visit_overloaded(self, left: Overloaded) -> bool:
935932
left_item,
936933
right_item,
937934
is_compat=self._is_subtype,
938-
is_proper_subtype=self.proper_subtype,
939935
ignore_return=True,
940936
ignore_pos_arg_names=self.subtype_context.ignore_pos_arg_names,
941937
strict_concatenate=strict_concat,
@@ -944,7 +940,6 @@ def visit_overloaded(self, left: Overloaded) -> bool:
944940
right_item,
945941
left_item,
946942
is_compat=self._is_subtype,
947-
is_proper_subtype=self.proper_subtype,
948943
ignore_return=True,
949944
ignore_pos_arg_names=self.subtype_context.ignore_pos_arg_names,
950945
strict_concatenate=strict_concat,
@@ -1363,7 +1358,6 @@ def is_callable_compatible(
13631358
right: CallableType,
13641359
*,
13651360
is_compat: Callable[[Type, Type], bool],
1366-
is_proper_subtype: bool,
13671361
is_compat_return: Callable[[Type, Type], bool] | None = None,
13681362
ignore_return: bool = False,
13691363
ignore_pos_arg_names: bool = False,
@@ -1523,7 +1517,6 @@ def g(x: int) -> int: ...
15231517
left,
15241518
right,
15251519
is_compat=is_compat,
1526-
is_proper_subtype=is_proper_subtype,
15271520
ignore_pos_arg_names=ignore_pos_arg_names,
15281521
allow_partial_overlap=allow_partial_overlap,
15291522
strict_concatenate_check=strict_concatenate_check,
@@ -1559,13 +1552,12 @@ def are_parameters_compatible(
15591552
right: Parameters | NormalizedCallableType,
15601553
*,
15611554
is_compat: Callable[[Type, Type], bool],
1562-
is_proper_subtype: bool,
15631555
ignore_pos_arg_names: bool = False,
15641556
allow_partial_overlap: bool = False,
15651557
strict_concatenate_check: bool = False,
15661558
) -> bool:
15671559
"""Helper function for is_callable_compatible, used for Parameter compatibility"""
1568-
if right.is_ellipsis_args and not is_proper_subtype:
1560+
if right.is_ellipsis_args:
15691561
return True
15701562

15711563
left_star = left.var_arg()
@@ -1574,9 +1566,9 @@ def are_parameters_compatible(
15741566
right_star2 = right.kw_arg()
15751567

15761568
# Treat "def _(*a: Any, **kw: Any) -> X" similarly to "Callable[..., X]"
1577-
if are_trivial_parameters(right) and not is_proper_subtype:
1569+
if are_trivial_parameters(right):
15781570
return True
1579-
trivial_suffix = is_trivial_suffix(right) and not is_proper_subtype
1571+
trivial_suffix = is_trivial_suffix(right)
15801572

15811573
# Match up corresponding arguments and check them for compatibility. In
15821574
# every pair (argL, argR) of corresponding arguments from L and R, argL must

test-data/unit/check-overloading.test

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6501,7 +6501,7 @@ eggs = lambda: 'eggs'
65016501
reveal_type(func(eggs)) # N: Revealed type is "def (builtins.str) -> builtins.str"
65026502

65036503
spam: Callable[..., str] = lambda x, y: 'baz'
6504-
reveal_type(func(spam)) # N: Revealed type is "def (*Any, **Any) -> Any"
6504+
reveal_type(func(spam)) # N: Revealed type is "def (*Any, **Any) -> builtins.str"
65056505
[builtins fixtures/paramspec.pyi]
65066506

65076507
[case testGenericOverloadOverlapWithType]
@@ -6673,23 +6673,3 @@ c2 = MyCallable("test")
66736673
reveal_type(c2) # N: Revealed type is "__main__.MyCallable[builtins.str]"
66746674
reveal_type(c2()) # should be int # N: Revealed type is "builtins.int"
66756675
[builtins fixtures/tuple.pyi]
6676-
6677-
[case testOverloadWithStarAnyFallback]
6678-
from typing import overload, Any
6679-
6680-
class A:
6681-
@overload
6682-
def f(self, e: str) -> str: ...
6683-
@overload
6684-
def f(self, *args: Any, **kwargs: Any) -> Any: ...
6685-
def f(self, *args, **kwargs):
6686-
pass
6687-
6688-
class B:
6689-
@overload
6690-
def f(self, e: str, **kwargs: Any) -> str: ...
6691-
@overload
6692-
def f(self, *args: Any, **kwargs: Any) -> Any: ...
6693-
def f(self, *args, **kwargs):
6694-
pass
6695-
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)