@@ -414,53 +414,56 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
414
414
def check_overlapping_overloads (self , defn : OverloadedFuncDef ) -> None :
415
415
# At this point we should have set the impl already, and all remaining
416
416
# items are decorators
417
- for i , item in enumerate (defn .items ):
418
- # TODO overloads involving decorators
419
- assert isinstance (item , Decorator )
420
- sig1 = self .function_type (item .func )
417
+ with experiments .strict_optional_set (True ):
418
+ for i , item in enumerate (defn .items ):
419
+ # TODO overloads involving decorators
420
+ assert isinstance (item , Decorator )
421
+ sig1 = self .function_type (item .func )
421
422
422
- for j , item2 in enumerate (defn .items [i + 1 :]):
423
- assert isinstance (item2 , Decorator )
424
- sig2 = self .function_type (item2 .func )
423
+ for j , item2 in enumerate (defn .items [i + 1 :]):
424
+ assert isinstance (item2 , Decorator )
425
+ sig2 = self .function_type (item2 .func )
425
426
426
- assert isinstance (sig1 , CallableType )
427
- assert isinstance (sig2 , CallableType )
427
+ assert isinstance (sig1 , CallableType )
428
+ assert isinstance (sig2 , CallableType )
428
429
429
- if not are_argument_counts_overlapping (sig1 , sig2 ):
430
- continue
431
-
432
- if if_overload_can_never_match (sig1 , sig2 ):
433
- self .msg .overloaded_signature_will_never_match (i + 1 , i + j + 2 , item2 .func )
434
- elif is_unsafe_overlapping_overload_signatures (sig1 , sig2 ):
435
- self .msg .overloaded_signatures_overlap (i + 1 , i + j + 2 , item .func )
436
- if defn .impl :
437
- if isinstance (defn .impl , FuncDef ):
438
- impl_type = defn .impl .type
439
- elif isinstance (defn .impl , Decorator ):
440
- impl_type = defn .impl .var .type
441
- else :
442
- assert False , "Impl isn't the right type"
443
- # This can happen if we've got an overload with a different
444
- # decorator too -- we gave up on the types.
445
- if impl_type is None or isinstance (impl_type , AnyType ) or sig1 is None :
446
- return
430
+ if not are_argument_counts_overlapping (sig1 , sig2 ):
431
+ continue
447
432
448
- assert isinstance (impl_type , CallableType )
449
- assert isinstance (sig1 , CallableType )
450
- if not is_callable_compatible (impl_type , sig1 ,
451
- is_compat = is_subtype , ignore_return = True ):
452
- self .msg .overloaded_signatures_arg_specific (i + 1 , defn .impl )
453
- impl_type_subst = impl_type
454
- if impl_type .variables :
455
- unified = unify_generic_callable (impl_type , sig1 , ignore_return = False )
456
- if unified is None :
457
- self .fail ("Type variable mismatch between " +
458
- "overload signature {} and implementation" .format (i + 1 ),
459
- defn .impl )
433
+ if overload_can_never_match (sig1 , sig2 ):
434
+ self .msg .overloaded_signature_will_never_match (
435
+ i + 1 , i + j + 2 , item2 .func )
436
+ elif is_unsafe_overlapping_overload_signatures (sig1 , sig2 ):
437
+ self .msg .overloaded_signatures_overlap (
438
+ i + 1 , i + j + 2 , item .func )
439
+ if defn .impl :
440
+ if isinstance (defn .impl , FuncDef ):
441
+ impl_type = defn .impl .type
442
+ elif isinstance (defn .impl , Decorator ):
443
+ impl_type = defn .impl .var .type
444
+ else :
445
+ assert False , "Impl isn't the right type"
446
+ # This can happen if we've got an overload with a different
447
+ # decorator too -- we gave up on the types.
448
+ if impl_type is None or isinstance (impl_type , AnyType ) or sig1 is None :
460
449
return
461
- impl_type_subst = unified
462
- if not is_subtype (sig1 .ret_type , impl_type_subst .ret_type ):
463
- self .msg .overloaded_signatures_ret_specific (i + 1 , defn .impl )
450
+
451
+ assert isinstance (impl_type , CallableType )
452
+ assert isinstance (sig1 , CallableType )
453
+ if not is_callable_compatible (impl_type , sig1 ,
454
+ is_compat = is_subtype , ignore_return = True ):
455
+ self .msg .overloaded_signatures_arg_specific (i + 1 , defn .impl )
456
+ impl_type_subst = impl_type
457
+ if impl_type .variables :
458
+ unified = unify_generic_callable (impl_type , sig1 , ignore_return = False )
459
+ if unified is None :
460
+ self .fail ("Type variable mismatch between " +
461
+ "overload signature {} and implementation" .format (i + 1 ),
462
+ defn .impl )
463
+ return
464
+ impl_type_subst = unified
465
+ if not is_subtype (sig1 .ret_type , impl_type_subst .ret_type ):
466
+ self .msg .overloaded_signatures_ret_specific (i + 1 , defn .impl )
464
467
465
468
# Here's the scoop about generators and coroutines.
466
469
#
@@ -3618,7 +3621,7 @@ def is_unsafe_overlapping_overload_signatures(signature: CallableType,
3618
3621
is_compat_return = lambda l , r : not is_subtype (r , l )))
3619
3622
3620
3623
3621
- def if_overload_can_never_match (signature : CallableType , other : CallableType ) -> bool :
3624
+ def overload_can_never_match (signature : CallableType , other : CallableType ) -> bool :
3622
3625
"""Check if the 'other' method can never be matched due to 'signature'.
3623
3626
3624
3627
This can happen if signature's parameters are all strictly broader then
0 commit comments