[red-knot] Minor improvements to property_tests.rs (#15440)

This commit is contained in:
Alex Waygood 2025-01-12 13:55:18 +00:00 committed by GitHub
parent ccfde37619
commit c8795fcb37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,7 +28,7 @@ use std::sync::{Arc, Mutex, MutexGuard, OnceLock};
use super::tests::Ty; use super::tests::Ty;
use crate::db::tests::{setup_db, TestDb}; use crate::db::tests::{setup_db, TestDb};
use crate::types::KnownClass; use crate::types::{IntersectionBuilder, KnownClass, Type, UnionType};
use quickcheck::{Arbitrary, Gen}; use quickcheck::{Arbitrary, Gen};
fn arbitrary_core_type(g: &mut Gen) -> Ty { fn arbitrary_core_type(g: &mut Gen) -> Ty {
@ -219,13 +219,20 @@ macro_rules! type_property_test {
}; };
} }
mod stable { fn intersection<'db>(db: &'db TestDb, s: Type<'db>, t: Type<'db>) -> Type<'db> {
use crate::db::tests::TestDb; IntersectionBuilder::new(db)
use crate::types::{KnownClass, Type, UnionType}; .add_positive(s)
.add_positive(t)
.build()
}
fn union<'db>(db: &'db TestDb, s: Type<'db>, t: Type<'db>) -> Type<'db> { fn union<'db>(db: &'db TestDb, s: Type<'db>, t: Type<'db>) -> Type<'db> {
UnionType::from_elements(db, [s, t]) UnionType::from_elements(db, [s, t])
} }
mod stable {
use super::union;
use crate::types::{KnownClass, Type};
// `T` is equivalent to itself. // `T` is equivalent to itself.
type_property_test!( type_property_test!(
@ -328,21 +335,7 @@ mod stable {
/// tests to the `stable` section. In the meantime, it can still be useful to run these /// tests to the `stable` section. In the meantime, it can still be useful to run these
/// tests (using [`types::property_tests::flaky`]), to see if there are any new obvious bugs. /// tests (using [`types::property_tests::flaky`]), to see if there are any new obvious bugs.
mod flaky { mod flaky {
use crate::{ use super::{intersection, union};
db::tests::TestDb,
types::{IntersectionBuilder, Type, UnionType},
};
fn intersection<'db>(db: &'db TestDb, s: Type<'db>, t: Type<'db>) -> Type<'db> {
IntersectionBuilder::new(db)
.add_positive(s)
.add_positive(t)
.build()
}
fn union<'db>(db: &'db TestDb, s: Type<'db>, t: Type<'db>) -> Type<'db> {
UnionType::from_elements(db, [s, t])
}
// Currently fails due to https://github.com/astral-sh/ruff/issues/14899 // Currently fails due to https://github.com/astral-sh/ruff/issues/14899
// `T` can be assigned to itself. // `T` can be assigned to itself.
@ -359,6 +352,7 @@ mod flaky {
); );
// `S <: T` and `T <: S` implies that `S` is equivalent to `T`. // `S <: T` and `T <: S` implies that `S` is equivalent to `T`.
// This very often passes now, but occasionally flakes due to https://github.com/astral-sh/ruff/issues/15380
type_property_test!( type_property_test!(
subtype_of_is_antisymmetric, db, subtype_of_is_antisymmetric, db,
forall types s, t. s.is_subtype_of(db, t) && t.is_subtype_of(db, s) => s.is_equivalent_to(db, t) forall types s, t. s.is_subtype_of(db, t) && t.is_subtype_of(db, s) => s.is_equivalent_to(db, t)