@@ -622,7 +622,10 @@ impl<'db> ClassType<'db> {
622622 Some ( spec) => {
623623 let tuple = spec. tuple ( db) ;
624624 let tuple_len = tuple. len ( ) ;
625+
625626 if tuple_len. minimum ( ) == 0 && tuple_len. maximum ( ) . is_none ( ) {
627+ // If the tuple has no length restrictions,
628+ // any iterable is allowed as long as the iterable has the correct element type.
626629 let mut tuple_elements = tuple. all_elements ( ) ;
627630 iterable_parameter = iterable_parameter. with_annotated_type (
628631 KnownClass :: Iterable
@@ -634,16 +637,24 @@ impl<'db> ClassType<'db> {
634637 "Tuple specialization should not have more than one element when it has no length restriction"
635638 ) ;
636639 } else {
640+ // But if the tuple is of a fixed length, or has a minimum length, we require a tuple rather
641+ // than an iterable, as a tuple is the only kind of iterable for which we can
642+ // specify a fixed length, or that the iterable must be at least a certain length.
637643 iterable_parameter =
638644 iterable_parameter. with_annotated_type ( Type :: instance ( db, self ) ) ;
639645 }
640646 }
641647 None => {
648+ // If the tuple isn't specialized at all, we allow any argument as long as it is iterable.
642649 iterable_parameter = iterable_parameter
643650 . with_annotated_type ( KnownClass :: Iterable . to_instance ( db) ) ;
644651 }
645652 }
646653
654+ // We allow the `iterable` parameter to be omitted for:
655+ // - a zero-length tuple
656+ // - an unspecialized tuple
657+ // - a tuple with no minimum length
647658 if specialization. is_none_or ( |spec| spec. tuple ( db) . len ( ) . minimum ( ) == 0 ) {
648659 iterable_parameter = iterable_parameter. with_default_type ( TupleType :: empty ( db) ) ;
649660 }
0 commit comments