Skip to content

Commit e16473d

Browse files
authored
[ty] Add a new property test: all types assignable to Iterable[object] should be considered iterable (#19186)
1 parent 220a584 commit e16473d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/ty_python_semantic/src/types/property_tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ mod flaky {
218218
use itertools::Itertools;
219219

220220
use super::{intersection, union};
221+
use crate::types::{KnownClass, Type};
221222

222223
// Negating `T` twice is equivalent to `T`.
223224
type_property_test!(
@@ -311,4 +312,14 @@ mod flaky {
311312
bottom_materialization_of_type_is_assigneble_to_type, db,
312313
forall types t. t.bottom_materialization(db).is_assignable_to(db, t)
313314
);
315+
316+
// Any type assignable to `Iterable[object]` should be considered iterable.
317+
//
318+
// Note that the inverse is not true, due to the fact that we recognize the old-style
319+
// iteration protocol as well as the new-style iteration protocol: not all objects that
320+
// we consider iterable are assignable to `Iterable[object]`.
321+
type_property_test!(
322+
all_type_assignable_to_iterable_are_iterable, db,
323+
forall types t. t.is_assignable_to(db, KnownClass::Iterable.to_specialized_instance(db, [Type::object(db)])) => t.try_iterate(db).is_ok()
324+
);
314325
}

0 commit comments

Comments
 (0)