From e16473d2601de8397c5f7fd21b8f92acf7061ec5 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 8 Jul 2025 10:54:06 +0100 Subject: [PATCH] [ty] Add a new property test: all types assignable to `Iterable[object]` should be considered iterable (#19186) --- crates/ty_python_semantic/src/types/property_tests.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/ty_python_semantic/src/types/property_tests.rs b/crates/ty_python_semantic/src/types/property_tests.rs index 5f071cbff5..8b5baa958e 100644 --- a/crates/ty_python_semantic/src/types/property_tests.rs +++ b/crates/ty_python_semantic/src/types/property_tests.rs @@ -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() + ); }