@@ -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-
315311def 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