[ty] Add a new property test: all types assignable to Iterable[object] should be considered iterable (#19186)

This commit is contained in:
Alex Waygood 2025-07-08 10:54:06 +01:00 committed by GitHub
parent 220a584c11
commit e16473d260
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -218,6 +218,7 @@ mod flaky {
use itertools::Itertools;
use super::{intersection, union};
use crate::types::{KnownClass, Type};
// Negating `T` twice is equivalent to `T`.
type_property_test!(
@ -311,4 +312,14 @@ mod flaky {
bottom_materialization_of_type_is_assigneble_to_type, db,
forall types t. t.bottom_materialization(db).is_assignable_to(db, t)
);
// Any type assignable to `Iterable[object]` should be considered iterable.
//
// Note that the inverse is not true, due to the fact that we recognize the old-style
// iteration protocol as well as the new-style iteration protocol: not all objects that
// we consider iterable are assignable to `Iterable[object]`.
type_property_test!(
all_type_assignable_to_iterable_are_iterable, db,
forall types t. t.is_assignable_to(db, KnownClass::Iterable.to_specialized_instance(db, [Type::object(db)])) => t.try_iterate(db).is_ok()
);
}