cleanup messages and TODOs

This commit is contained in:
Aria Desires 2025-07-17 12:27:55 -04:00 committed by David Peter
parent 27fd7cb0d8
commit 8cdb5f8d8b
2 changed files with 28 additions and 13 deletions

View File

@ -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 {

View File

@ -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);
}