Skip to content

Commit 376e270

Browse files
committed
Add Type::is_deprecated
1 parent 5e580c8 commit 376e270

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

crates/ty_ide/src/completion.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,9 @@ impl<'db> Completion<'db> {
303303
}
304304
}
305305

306-
// TODO: Not sure about this. I need to pass the deprecated value to relevance and this seems
307-
// like the way
308-
#[expect(clippy::struct_excessive_bools)]
309306
/// A builder for construction a `Completion`.
310307
#[derive(Debug)]
308+
#[expect(clippy::struct_excessive_bools)]
311309
struct CompletionBuilder<'db> {
312310
// See comments on `Completion` for the meaning of fields.
313311
name: Name,
@@ -420,13 +418,7 @@ impl<'db> CompletionBuilder<'db> {
420418
);
421419
}
422420

423-
self.deprecated = {
424-
match ty {
425-
Type::FunctionLiteral(f) => f.implementation_deprecated(db).is_some(),
426-
Type::ClassLiteral(c) => c.deprecated(db).is_some(),
427-
_ => false,
428-
}
429-
};
421+
self.deprecated = ty.is_deprecated(db);
430422
}
431423
let kind = self
432424
.kind

crates/ty_python_semantic/src/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,15 @@ impl<'db> Type<'db> {
10531053
}
10541054
}
10551055

1056+
/// Returns whether this type is marked as deprecated via `@warnings.deprecated`.
1057+
pub fn is_deprecated(&self, db: &'db dyn Db) -> bool {
1058+
match self {
1059+
Type::FunctionLiteral(f) => f.implementation_deprecated(db).is_some(),
1060+
Type::ClassLiteral(c) => c.deprecated(db).is_some(),
1061+
_ => false,
1062+
}
1063+
}
1064+
10561065
/// If the type is a specialized instance of the given `KnownClass`, returns the specialization.
10571066
pub(crate) fn known_specialization(
10581067
&self,

crates/ty_python_semantic/src/types/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl<'db> ClassLiteral<'db> {
581581
}
582582

583583
/// Returns the deprecated info if this class is deprecated.
584-
pub fn deprecated(self, db: &'db dyn Db) -> Option<DeprecatedInstance<'db>> {
584+
pub(crate) fn deprecated(self, db: &'db dyn Db) -> Option<DeprecatedInstance<'db>> {
585585
self.as_static().and_then(|class| class.deprecated(db))
586586
}
587587

crates/ty_python_semantic/src/types/function.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,10 @@ impl<'db> FunctionType<'db> {
10091009
/// If the implementation of this function is deprecated, returns the `@warnings.deprecated`.
10101010
///
10111011
/// Checking if an overload is deprecated requires deeper call analysis.
1012-
pub fn implementation_deprecated(self, db: &'db dyn Db) -> Option<DeprecatedInstance<'db>> {
1012+
pub(crate) fn implementation_deprecated(
1013+
self,
1014+
db: &'db dyn Db,
1015+
) -> Option<DeprecatedInstance<'db>> {
10131016
self.literal(db).implementation_deprecated(db)
10141017
}
10151018

0 commit comments

Comments
 (0)