mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:34:57 +00:00
[ty] Add a new property test: all types assignable to Iterable[object]
should be considered iterable (#19186)
This commit is contained in:
parent
220a584c11
commit
e16473d260
1 changed files with 11 additions and 0 deletions
|
@ -218,6 +218,7 @@ mod flaky {
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use super::{intersection, union};
|
use super::{intersection, union};
|
||||||
|
use crate::types::{KnownClass, Type};
|
||||||
|
|
||||||
// Negating `T` twice is equivalent to `T`.
|
// Negating `T` twice is equivalent to `T`.
|
||||||
type_property_test!(
|
type_property_test!(
|
||||||
|
@ -311,4 +312,14 @@ mod flaky {
|
||||||
bottom_materialization_of_type_is_assigneble_to_type, db,
|
bottom_materialization_of_type_is_assigneble_to_type, db,
|
||||||
forall types t. t.bottom_materialization(db).is_assignable_to(db, t)
|
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()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue