Compare commits

...

3 Commits

Author SHA1 Message Date
Carl Meyer
535e7f2d37 No-op change to trigger CI 2025-09-12 13:28:43 -07:00
Carl Meyer
7cb3f45b94 clippy 2025-09-12 13:21:45 -07:00
Carl Meyer
af1b14cf28 [ty] add cycle handling to BoundMethodType::into_callable_type() 2025-09-12 13:09:36 -07:00
3 changed files with 26 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
/// No-op change.
use infer::nearest_enclosing_class;
use itertools::{Either, Itertools};
use ruff_db::parsed::parsed_module;
@@ -8938,6 +8939,23 @@ fn walk_bound_method_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>(
visitor.visit_type(db, method.self_instance(db));
}
#[allow(clippy::trivially_copy_pass_by_ref)]
fn into_callable_type_cycle_recover<'db>(
_db: &'db dyn Db,
_value: &CallableType<'db>,
_count: u32,
_self: BoundMethodType<'db>,
) -> salsa::CycleRecoveryAction<CallableType<'db>> {
salsa::CycleRecoveryAction::Iterate
}
fn into_callable_type_cycle_initial<'db>(
db: &'db dyn Db,
_self: BoundMethodType<'db>,
) -> CallableType<'db> {
CallableType::bottom(db)
}
#[salsa::tracked]
impl<'db> BoundMethodType<'db> {
/// Returns the type that replaces any `typing.Self` annotations in the bound method signature.
@@ -8951,7 +8969,7 @@ impl<'db> BoundMethodType<'db> {
self_instance
}
#[salsa::tracked(heap_size=ruff_memory_usage::heap_size)]
#[salsa::tracked(cycle_fn=into_callable_type_cycle_recover, cycle_initial=into_callable_type_cycle_initial, heap_size=ruff_memory_usage::heap_size)]
pub(crate) fn into_callable_type(self, db: &'db dyn Db) -> CallableType<'db> {
let function = self.function(db);
let self_instance = self.typing_self_type(db);
@@ -9089,9 +9107,8 @@ impl<'db> CallableType<'db> {
///
/// Specifically, this represents a callable type with a single signature:
/// `(*args: object, **kwargs: object) -> Never`.
#[cfg(test)]
pub(crate) fn bottom(db: &'db dyn Db) -> Type<'db> {
Self::single(db, Signature::bottom())
pub(crate) fn bottom(db: &'db dyn Db) -> CallableType<'db> {
Self::new(db, CallableSignature::bottom(), false)
}
/// Return a "normalized" version of this `Callable` type.

View File

@@ -158,7 +158,7 @@ mod stable {
type_property_test!(
bottom_callable_is_subtype_of_all_callable, db,
forall types t. t.is_callable_type()
=> CallableType::bottom(db).is_subtype_of(db, t)
=> Type::Callable(CallableType::bottom(db)).is_subtype_of(db, t)
);
// `T` can be assigned to itself.

View File

@@ -43,6 +43,10 @@ impl<'db> CallableSignature<'db> {
}
}
pub(crate) fn bottom() -> Self {
Self::single(Signature::bottom())
}
/// Creates a new `CallableSignature` from an iterator of [`Signature`]s. Returns a
/// non-callable signature if the iterator is empty.
pub(crate) fn from_overloads<I>(overloads: I) -> Self