Skip to content

Commit 5c3ec54

Browse files
committed
Try without pre-filter
1 parent 80db966 commit 5c3ec54

File tree

3 files changed

+12
-68
lines changed

3 files changed

+12
-68
lines changed

mypy/checkmember.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
freeze_all_type_vars,
4646
function_type,
4747
get_all_type_vars,
48-
is_valid_self_type_best_effort,
4948
make_simplified_union,
5049
supported_self_type,
5150
tuple_fallback,
@@ -1050,23 +1049,6 @@ def f(self: S) -> T: ...
10501049
if is_classmethod:
10511050
dispatched_arg_type = TypeType.make_normalized(dispatched_arg_type)
10521051

1053-
if isinstance(functype, Overloaded):
1054-
p_dispatched_arg_type = get_proper_type(dispatched_arg_type)
1055-
filtered_items = []
1056-
for c in items:
1057-
if isinstance(p_dispatched_arg_type, Instance):
1058-
# Filter based on whether declared self type can match actual object type.
1059-
# For example, if self has type C[int] and method is accessed on a C[str] value,
1060-
# omit this item. This is best effort first pass filter obvious mismatches for
1061-
# performance reasons.
1062-
keep = is_valid_self_type_best_effort(c, p_dispatched_arg_type)
1063-
else:
1064-
keep = True
1065-
if keep:
1066-
filtered_items.append(c)
1067-
if len(filtered_items) != 0:
1068-
items = filtered_items
1069-
10701052
for item in items:
10711053
if not item.arg_types or item.arg_kinds[0] not in (ARG_POS, ARG_STAR):
10721054
# No positional first (self) argument (*args is okay).

mypy/meet.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ def is_object(t: ProperType) -> bool:
291291
return isinstance(t, Instance) and t.type.fullname == "builtins.object"
292292

293293

294+
def is_none_typevarlike_overlap(t1: ProperType, t2: ProperType) -> bool:
295+
return isinstance(t1, NoneType) and isinstance(t2, TypeVarLikeType)
296+
297+
298+
def is_none_object_overlap(t1: ProperType, t2: ProperType) -> bool:
299+
return (
300+
isinstance(t1, NoneType)
301+
and isinstance(t2, Instance)
302+
and t2.type.fullname == "builtins.object"
303+
)
304+
305+
294306
def is_overlapping_types(
295307
left: Type,
296308
right: Type,
@@ -382,14 +394,6 @@ def _is_overlapping_types(left: Type, right: Type) -> bool:
382394
):
383395
return True
384396

385-
def is_none_object_overlap(t1: Type, t2: Type) -> bool:
386-
t1, t2 = get_proper_types((t1, t2))
387-
return (
388-
isinstance(t1, NoneType)
389-
and isinstance(t2, Instance)
390-
and t2.type.fullname == "builtins.object"
391-
)
392-
393397
if overlap_for_overloads:
394398
if is_none_object_overlap(left, right) or is_none_object_overlap(right, left):
395399
return False
@@ -419,10 +423,6 @@ def _is_subtype(left: Type, right: Type) -> bool:
419423
# If both types are singleton variants (and are not TypeVarLikes), we've hit the base case:
420424
# we skip these checks to avoid infinitely recursing.
421425

422-
def is_none_typevarlike_overlap(t1: Type, t2: Type) -> bool:
423-
t1, t2 = get_proper_types((t1, t2))
424-
return isinstance(t1, NoneType) and isinstance(t2, TypeVarLikeType)
425-
426426
if prohibit_none_typevar_overlap:
427427
if is_none_typevarlike_overlap(left, right) or is_none_typevarlike_overlap(right, left):
428428
return False

mypy/typeops.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from mypy.expandtype import expand_type, expand_type_by_instance
1717
from mypy.maptype import map_instance_to_supertype
1818
from mypy.nodes import (
19-
ARG_OPT,
2019
ARG_POS,
2120
ARG_STAR,
2221
ARG_STAR2,
@@ -492,43 +491,6 @@ class B(A): pass
492491
return cast(F, res)
493492

494493

495-
def is_valid_self_type_best_effort(c: CallableType, self_type: Instance) -> bool:
496-
"""Quickly check if self_type might match the self in a callable.
497-
498-
Avoid performing any complex type operations. This is performance-critical.
499-
500-
Default to returning True if we don't know (or it would be too expensive).
501-
"""
502-
if (
503-
self_type.args
504-
and c.arg_types
505-
and isinstance((arg_type := get_proper_type(c.arg_types[0])), Instance)
506-
and c.arg_kinds[0] in (ARG_POS, ARG_OPT)
507-
and arg_type.args
508-
and self_type.type.fullname != "functools._SingleDispatchCallable"
509-
):
510-
if self_type.type is not arg_type.type:
511-
# We can't map to supertype, since it could trigger expensive checks for
512-
# protocol types, so we consevatively assume this is fine.
513-
return True
514-
515-
# Fast path: no explicit annotation on self
516-
if all(
517-
(
518-
type(arg) is TypeVarType
519-
and type(arg.upper_bound) is Instance
520-
and arg.upper_bound.type.fullname == "builtins.object"
521-
)
522-
for arg in arg_type.args
523-
):
524-
return True
525-
526-
from mypy.meet import is_overlapping_types
527-
528-
return is_overlapping_types(self_type, c.arg_types[0])
529-
return True
530-
531-
532494
def erase_to_bound(t: Type) -> Type:
533495
# TODO: use value restrictions to produce a union?
534496
t = get_proper_type(t)

0 commit comments

Comments
 (0)