From 8cdb5f8d8be937ca2c356b182f41fce2ecb593b7 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Thu, 17 Jul 2025 12:27:55 -0400 Subject: [PATCH] cleanup messages and TODOs --- crates/ty_python_semantic/src/types.rs | 25 ++++++++++++++++---- crates/ty_python_semantic/src/types/infer.rs | 16 ++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 1b5f766faf..4b5e88eea9 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -5882,9 +5882,8 @@ fn walk_known_instance_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( KnownInstanceType::TypeAliasType(type_alias) => { visitor.visit_type_alias_type(db, type_alias); } - KnownInstanceType::Deprecated(_deprecated) => { - // TODO(Gankra): do we need this? - // visitor.visit_deprecated_type(db, deprecated); + KnownInstanceType::Deprecated(_) => { + // Nothing to visit } } } @@ -5902,8 +5901,9 @@ impl<'db> KnownInstanceType<'db> { Self::TypeAliasType(type_alias) => { Self::TypeAliasType(type_alias.normalized_impl(db, visitor)) } - // TODO(Gankra): do we need this - Self::Deprecated(deprecated) => Self::Deprecated(deprecated), + Self::Deprecated(deprecated) => { + Self::Deprecated(deprecated.normalized_impl(db, visitor)) + } } } @@ -6261,6 +6261,21 @@ pub struct DeprecatedInstance<'db> { // The Salsa heap is tracked separately. impl get_size2::GetSize for DeprecatedInstance<'_> {} +impl<'db> DeprecatedInstance<'db> { + pub(crate) fn normalized_impl( + self, + db: &'db dyn Db, + _visitor: &mut TypeTransformer<'db>, + ) -> Self { + Self::new( + db, + // StringLiteralType has no normalization to do + self.message(db), + self.definition(db), + ) + } +} + /// Whether this typecar was created via the legacy `TypeVar` constructor, or using PEP 695 syntax. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum TypeVarKind { diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index c46204295d..8e18eae292 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -2319,7 +2319,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { Type::KnownInstance(KnownInstanceType::Deprecated(deprecated_inst)) => { // This isn't picked up by FunctionDecorators so we need to continue here // to avoid having the KnownInstanceType get type checked as it's not callable - // TODO(Gankra): we shouldn't be losing the fact that it *is* callable + // FIXME: we shouldn't be losing the fact that a KnownInstance *is* callable! deprecated = Some(deprecated_inst); continue; } @@ -5857,14 +5857,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let message = deprecated.message(self.db()).value(self.db()); let class_name = class_literal.name(self.db()); - let mut diag = builder.into_diagnostic(format_args!( - r#"The class "{class_name}" is deprecated: {message}"# - )); + let mut diag = + builder.into_diagnostic(format_args!(r#"The class "{class_name}" is deprecated"#)); + diag.set_primary_message(message); diag.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated); return; } - // Next handle methods + // Next handle functions let function = match ty { Type::FunctionLiteral(function) => function, Type::BoundMethod(bound) => bound.function(self.db()), @@ -5888,9 +5888,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let message = deprecated.message(self.db()).value(self.db()); let func_name = function.name(self.db()); - let mut diag = builder.into_diagnostic(format_args!( - r#"The function "{func_name}" is deprecated: {message}"# - )); + let mut diag = + builder.into_diagnostic(format_args!(r#"The function "{func_name}" is deprecated"#)); + diag.set_primary_message(message); diag.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated); }