Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// No-op change.
use infer::nearest_enclosing_class;
use itertools::{Either, Itertools};
use ruff_db::parsed::parsed_module;
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_python_semantic/src/types/property_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions crates/ty_python_semantic/src/types/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading