Skip to content

Commit 39156e0

Browse files
authored
Remove prohibit_none_typevar_overlap (#20864)
Noticed this seems to be useless while investigating a fix for narrowing with TypeVars
1 parent 270a01d commit 39156e0

File tree

3 files changed

+4
-27
lines changed

3 files changed

+4
-27
lines changed

mypy/checker.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9397,13 +9397,7 @@ def is_overlapping_types_for_overload(left: Type, right: Type) -> bool:
93979397
# def foo(x: None) -> None: ..
93989398
# @overload
93999399
# def foo(x: T) -> Foo[T]: ...
9400-
return is_overlapping_types(
9401-
left,
9402-
right,
9403-
ignore_promotions=True,
9404-
prohibit_none_typevar_overlap=True,
9405-
overlap_for_overloads=True,
9406-
)
9400+
return is_overlapping_types(left, right, ignore_promotions=True, overlap_for_overloads=True)
94079401

94089402

94099403
def is_private(node_name: str) -> bool:

mypy/checkexpr.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6367,9 +6367,7 @@ def narrow_type_from_binder(
63676367
isinstance(get_proper_type(known_type), AnyType) and self.chk.current_node_deferred
63686368
):
63696369
# Note: this call should match the one in narrow_declared_type().
6370-
if skip_non_overlapping and not is_overlapping_types(
6371-
known_type, restriction, prohibit_none_typevar_overlap=True
6372-
):
6370+
if skip_non_overlapping and not is_overlapping_types(known_type, restriction):
63736371
return None
63746372
narrowed = narrow_declared_type(known_type, restriction)
63756373
if isinstance(get_proper_type(narrowed), UninhabitedType):

mypy/meet.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
173173
return declared.copy_modified(
174174
upper_bound=narrow_declared_type(declared.upper_bound, original_narrowed)
175175
)
176-
elif not is_overlapping_types(declared, narrowed, prohibit_none_typevar_overlap=True):
176+
elif not is_overlapping_types(declared, narrowed):
177177
if state.strict_optional:
178178
return UninhabitedType()
179179
else:
@@ -308,10 +308,6 @@ def is_object(t: ProperType) -> bool:
308308
return isinstance(t, Instance) and t.type.fullname == "builtins.object"
309309

310310

311-
def is_none_typevarlike_overlap(t1: ProperType, t2: ProperType) -> bool:
312-
return isinstance(t1, NoneType) and isinstance(t2, TypeVarLikeType)
313-
314-
315311
def is_none_object_overlap(t1: ProperType, t2: ProperType) -> bool:
316312
return (
317313
isinstance(t1, NoneType)
@@ -337,15 +333,12 @@ def is_overlapping_types(
337333
left: Type,
338334
right: Type,
339335
ignore_promotions: bool = False,
340-
prohibit_none_typevar_overlap: bool = False,
341336
overlap_for_overloads: bool = False,
342337
seen_types: set[tuple[Type, Type]] | None = None,
343338
) -> bool:
344339
"""Can a value of type 'left' also be of type 'right' or vice-versa?
345340
346341
If 'ignore_promotions' is True, we ignore promotions while checking for overlaps.
347-
If 'prohibit_none_typevar_overlap' is True, we disallow None from overlapping with
348-
TypeVars (in both strict-optional and non-strict-optional mode).
349342
If 'overlap_for_overloads' is True, we check for overlaps more strictly (to avoid false
350343
positives), for example: None only overlaps with explicitly optional types, Any
351344
doesn't overlap with anything except object, we don't ignore positional argument names.
@@ -433,10 +426,6 @@ def is_overlapping_types(
433426
# If both types are singleton variants (and are not TypeVarLikes), we've hit the base case:
434427
# we skip these checks to avoid infinitely recursing.
435428

436-
if prohibit_none_typevar_overlap:
437-
if is_none_typevarlike_overlap(left, right) or is_none_typevarlike_overlap(right, left):
438-
return False
439-
440429
def _is_overlapping_types(left: Type, right: Type) -> bool:
441430
"""Encode the kind of overlapping check to perform.
442431
@@ -446,7 +435,6 @@ def _is_overlapping_types(left: Type, right: Type) -> bool:
446435
left,
447436
right,
448437
ignore_promotions=ignore_promotions,
449-
prohibit_none_typevar_overlap=prohibit_none_typevar_overlap,
450438
overlap_for_overloads=overlap_for_overloads,
451439
seen_types=seen_types.copy(),
452440
)
@@ -662,10 +650,7 @@ def is_overlapping_erased_types(
662650
) -> bool:
663651
"""The same as 'is_overlapping_erased_types', except the types are erased first."""
664652
return is_overlapping_types(
665-
erase_type(left),
666-
erase_type(right),
667-
ignore_promotions=ignore_promotions,
668-
prohibit_none_typevar_overlap=True,
653+
erase_type(left), erase_type(right), ignore_promotions=ignore_promotions
669654
)
670655

671656

0 commit comments

Comments
 (0)