red_knot_python_semantic: rename `lint()` and `report()`

... to `report_lint()` and `report_diagnostic()`. And rename the old
`report_lint()` to `report_lint_old()`.
This commit is contained in:
Andrew Gallant 2025-04-10 13:07:27 -04:00 committed by Andrew Gallant
parent 81045758d3
commit bd58135b0d
7 changed files with 127 additions and 127 deletions

View File

@ -4481,7 +4481,7 @@ impl<'db> InvalidTypeExpressionError<'db> {
invalid_expressions,
} = self;
for error in invalid_expressions {
context.report_lint(
context.report_lint_old(
&INVALID_TYPE_FORM,
node,
format_args!("{}", error.reason(context.db())),
@ -4715,7 +4715,7 @@ impl<'db> ContextManagerError<'db> {
} => format_call_dunder_errors(enter_error, "__enter__", exit_error, "__exit__"),
};
context.report_lint(
context.report_lint_old(
&INVALID_CONTEXT_MANAGER,
context_expression_node,
format_args!(
@ -4818,7 +4818,7 @@ impl<'db> IterationError<'db> {
let db = context.db();
let report_not_iterable = |arguments: std::fmt::Arguments| {
context.report_lint(&NOT_ITERABLE, iterable_node, arguments);
context.report_lint_old(&NOT_ITERABLE, iterable_node, arguments);
};
// TODO: for all of these error variants, the "explanation" for the diagnostic
@ -5096,7 +5096,7 @@ impl<'db> BoolError<'db> {
Self::IncorrectArguments {
not_boolable_type, ..
} => {
context.report_lint(
context.report_lint_old(
&UNSUPPORTED_BOOL_CONVERSION,
condition,
format_args!(
@ -5109,7 +5109,7 @@ impl<'db> BoolError<'db> {
not_boolable_type,
return_type,
} => {
context.report_lint(
context.report_lint_old(
&UNSUPPORTED_BOOL_CONVERSION,
condition,
format_args!(
@ -5120,7 +5120,7 @@ impl<'db> BoolError<'db> {
);
}
Self::NotCallable { not_boolable_type } => {
context.report_lint(
context.report_lint_old(
&UNSUPPORTED_BOOL_CONVERSION,
condition,
format_args!(
@ -5136,7 +5136,7 @@ impl<'db> BoolError<'db> {
.find_map(|element| element.try_bool(context.db()).err())
.unwrap();
context.report_lint(
context.report_lint_old(
&UNSUPPORTED_BOOL_CONVERSION,
condition,
format_args!(
@ -5148,7 +5148,7 @@ impl<'db> BoolError<'db> {
}
Self::Other { not_boolable_type } => {
context.report_lint(
context.report_lint_old(
&UNSUPPORTED_BOOL_CONVERSION,
condition,
format_args!(
@ -5189,7 +5189,7 @@ impl<'db> ConstructorCallError<'db> {
// If we are using vendored typeshed, it should be impossible to have missing
// or unbound `__init__` method on a class, as all classes have `object` in MRO.
// Thus the following may only trigger if a custom typeshed is used.
context.report_lint(
context.report_lint_old(
&CALL_POSSIBLY_UNBOUND_METHOD,
context_expression_node,
format_args!(
@ -5199,7 +5199,7 @@ impl<'db> ConstructorCallError<'db> {
);
}
CallDunderError::PossiblyUnbound(bindings) => {
context.report_lint(
context.report_lint_old(
&CALL_POSSIBLY_UNBOUND_METHOD,
context_expression_node,
format_args!(
@ -5222,7 +5222,7 @@ impl<'db> ConstructorCallError<'db> {
unreachable!("`__new__` method may not be called if missing");
}
CallDunderError::PossiblyUnbound(bindings) => {
context.report_lint(
context.report_lint_old(
&CALL_POSSIBLY_UNBOUND_METHOD,
context_expression_node,
format_args!(

View File

@ -170,7 +170,7 @@ impl<'db> Bindings<'db> {
// If all union elements are not callable, report that the union as a whole is not
// callable.
if self.into_iter().all(|b| !b.is_callable()) {
context.report_lint(
context.report_lint_old(
&CALL_NON_CALLABLE,
node,
format_args!(
@ -183,7 +183,7 @@ impl<'db> Bindings<'db> {
for (index, conflicting_form) in self.conflicting_forms.iter().enumerate() {
if *conflicting_form {
context.report_lint(
context.report_lint_old(
&CONFLICTING_ARGUMENT_FORMS,
BindingError::get_node(node, Some(index)),
format_args!("Argument is used as both a value and a type form in call"),
@ -764,7 +764,7 @@ impl<'db> CallableBinding<'db> {
fn report_diagnostics(&self, context: &InferContext<'db>, node: ast::AnyNodeRef) {
if !self.is_callable() {
context.report_lint(
context.report_lint_old(
&CALL_NON_CALLABLE,
node,
format_args!(
@ -776,7 +776,7 @@ impl<'db> CallableBinding<'db> {
}
if self.dunder_call_is_possibly_unbound {
context.report_lint(
context.report_lint_old(
&CALL_NON_CALLABLE,
node,
format_args!(
@ -789,7 +789,7 @@ impl<'db> CallableBinding<'db> {
let callable_description = CallableDescription::new(context.db(), self.callable_type);
if self.overloads.len() > 1 {
context.report_lint(
context.report_lint_old(
&NO_MATCHING_OVERLOAD,
node,
format_args!(
@ -1238,7 +1238,7 @@ impl<'db> BindingError<'db> {
expected_ty,
provided_ty,
} => {
let Some(builder) = context.lint(&INVALID_ARGUMENT_TYPE) else {
let Some(builder) = context.report_lint(&INVALID_ARGUMENT_TYPE) else {
return;
};
@ -1268,7 +1268,7 @@ impl<'db> BindingError<'db> {
expected_positional_count,
provided_positional_count,
} => {
context.report_lint(
context.report_lint_old(
&TOO_MANY_POSITIONAL_ARGUMENTS,
Self::get_node(node, *first_excess_argument_index),
format_args!(
@ -1285,7 +1285,7 @@ impl<'db> BindingError<'db> {
Self::MissingArguments { parameters } => {
let s = if parameters.0.len() == 1 { "" } else { "s" };
context.report_lint(
context.report_lint_old(
&MISSING_ARGUMENT,
node,
format_args!(
@ -1303,7 +1303,7 @@ impl<'db> BindingError<'db> {
argument_name,
argument_index,
} => {
context.report_lint(
context.report_lint_old(
&UNKNOWN_ARGUMENT,
Self::get_node(node, *argument_index),
format_args!(
@ -1321,7 +1321,7 @@ impl<'db> BindingError<'db> {
argument_index,
parameter,
} => {
context.report_lint(
context.report_lint_old(
&PARAMETER_ALREADY_ASSIGNED,
Self::get_node(node, *argument_index),
format_args!(
@ -1336,7 +1336,7 @@ impl<'db> BindingError<'db> {
}
Self::InternalCallError(reason) => {
context.report_lint(
context.report_lint_old(
&CALL_NON_CALLABLE,
Self::get_node(node, None),
format_args!(

View File

@ -74,7 +74,7 @@ impl<'db> InferContext<'db> {
}
/// Reports a lint located at `ranged`.
pub(super) fn report_lint<T>(
pub(super) fn report_lint_old<T>(
&self,
lint: &'static LintMetadata,
ranged: T,
@ -82,7 +82,7 @@ impl<'db> InferContext<'db> {
) where
T: Ranged,
{
let Some(builder) = self.lint(lint) else {
let Some(builder) = self.report_lint(lint) else {
return;
};
let mut reporter = builder.build("");
@ -109,8 +109,8 @@ impl<'db> InferContext<'db> {
/// constructed diagnostic will be ignored.
///
/// If callers need to create a non-lint diagnostic, you'll want to use
/// the lower level `InferContext::report` routine.
pub(super) fn lint<'ctx>(
/// the lower level `InferContext::report_diagnostic` routine.
pub(super) fn report_lint<'ctx>(
&'ctx self,
lint: &'static LintMetadata,
) -> Option<LintReporterBuilder<'ctx, 'db>> {
@ -122,7 +122,7 @@ impl<'db> InferContext<'db> {
/// This only returns a reporter builder if the current context
/// allows a diagnostic with the given information to be added.
/// In general, the requirements here are quite a bit less than
/// for `InferContext::lint`, since this routine doesn't take rule
/// for `InferContext::report_lint`, since this routine doesn't take rule
/// selection into account.
///
/// After using the builder to make a reporter, once the reporter is
@ -130,8 +130,8 @@ impl<'db> InferContext<'db> {
/// something in the diagnostic that excludes it.
///
/// Callers should generally prefer adding a lint diagnostic via
/// `InferContext::lint` whenever possible.
pub(super) fn report<'ctx>(
/// `InferContext::report_lint` whenever possible.
pub(super) fn report_diagnostic<'ctx>(
&'ctx self,
id: DiagnosticId,
severity: Severity,
@ -205,7 +205,7 @@ pub(crate) enum InNoTypeCheck {
/// An abstraction for reporting lints as diagnostics.
///
/// Callers can build a reporter via `InferContext::lint`.
/// Callers can build a reporter via `InferContext::report_lint`.
///
/// A reporter encapsulates the logic for determining if a diagnostic *should*
/// be reported according to the environment, configuration, and any relevant
@ -225,8 +225,8 @@ pub(crate) enum InNoTypeCheck {
///
/// If callers need to report a diagnostic with an identifier type other
/// than `DiagnosticId::Lint`, then they should use the more general
/// `InferContext::report` API. But note that this API will not take rule
/// selection or suppressions into account.
/// `InferContext::report_diagnostic` API. But note that this API will not take
/// rule selection or suppressions into account.
pub(super) struct LintReporter<'db, 'ctx> {
/// The typing context.
ctx: &'ctx InferContext<'db>,
@ -307,7 +307,7 @@ impl Drop for LintReporter<'_, '_> {
///
/// This type exists to separate the phases of "check if a diagnostic should
/// be reported" and "build the actual diagnostic." It's why, for example,
/// `InferContext::lint` only requires a `LintMetadata`, but this builder
/// `InferContext::report_lint` only requires a `LintMetadata`, but this builder
/// further requires a message before one can mutate the diagnostic. This is
/// because the `LintMetadata` can be used to derive the diagnostic ID and its
/// severity (based on configuration). Combined with a message you get the
@ -366,7 +366,7 @@ impl<'db, 'ctx> LintReporterBuilder<'db, 'ctx> {
/// An abstraction for reporting diagnostics.
///
/// Callers can build a reporter via `InferContext::report`.
/// Callers can build a reporter via `InferContext::report_diagnostic`.
///
/// A reporter encapsulates the logic for determining if a diagnostic *should*
/// be reported according to the environment, configuration, and any relevant
@ -377,8 +377,8 @@ impl<'db, 'ctx> LintReporterBuilder<'db, 'ctx> {
/// The diagnostic is added to the typing context, if appropriate, when this
/// reporter is dropped.
///
/// Callers likely should use `LintReporter` via `InferContext::lint` instead.
/// This reporter is only intended for use with non-lint diagnostics.
/// Callers likely should use `LintReporter` via `InferContext::report_lint`
/// instead. This reporter is only intended for use with non-lint diagnostics.
pub(super) struct DiagnosticReporter<'db, 'ctx> {
ctx: &'ctx InferContext<'db>,
/// The diagnostic that we want to report.
@ -429,10 +429,10 @@ impl Drop for DiagnosticReporter<'_, '_> {
///
/// This type exists to separate the phases of "check if a diagnostic should
/// be reported" and "build the actual diagnostic." It's why, for example,
/// `InferContext::report` only requires an ID and a severity, but this builder
/// further requires a message (with those three things being the minimal
/// amount of information with which to construct a diagnostic) before one can
/// mutate the diagnostic.
/// `InferContext::report_diagnostic` only requires an ID and a severity, but
/// this builder further requires a message (with those three things being the
/// minimal amount of information with which to construct a diagnostic) before
/// one can mutate the diagnostic.
pub(super) struct DiagnosticReporterBuilder<'db, 'ctx> {
ctx: &'ctx InferContext<'db>,
id: DiagnosticId,

View File

@ -966,7 +966,7 @@ pub(super) fn report_index_out_of_bounds(
length: usize,
index: i64,
) {
context.report_lint(
context.report_lint_old(
&INDEX_OUT_OF_BOUNDS,
node,
format_args!(
@ -983,7 +983,7 @@ pub(super) fn report_non_subscriptable(
non_subscriptable_ty: Type,
method: &str,
) {
context.report_lint(
context.report_lint_old(
&NON_SUBSCRIPTABLE,
node,
format_args!(
@ -999,7 +999,7 @@ pub(super) fn report_unresolved_module<'db>(
level: u32,
module: Option<&str>,
) {
context.report_lint(
context.report_lint_old(
&UNRESOLVED_IMPORT,
import_node.into(),
format_args!(
@ -1011,7 +1011,7 @@ pub(super) fn report_unresolved_module<'db>(
}
pub(super) fn report_slice_step_size_zero(context: &InferContext, node: AnyNodeRef) {
context.report_lint(
context.report_lint_old(
&ZERO_STEPSIZE_IN_SLICE,
node,
format_args!("Slice step size can not be zero"),
@ -1026,17 +1026,17 @@ fn report_invalid_assignment_with_message(
) {
match target_ty {
Type::ClassLiteral(class) => {
context.report_lint(&INVALID_ASSIGNMENT, node, format_args!(
context.report_lint_old(&INVALID_ASSIGNMENT, node, format_args!(
"Implicit shadowing of class `{}`; annotate to make it explicit if this is intentional",
class.name(context.db())));
}
Type::FunctionLiteral(function) => {
context.report_lint(&INVALID_ASSIGNMENT, node, format_args!(
context.report_lint_old(&INVALID_ASSIGNMENT, node, format_args!(
"Implicit shadowing of function `{}`; annotate to make it explicit if this is intentional",
function.name(context.db())));
}
_ => {
context.report_lint(&INVALID_ASSIGNMENT, node, message);
context.report_lint_old(&INVALID_ASSIGNMENT, node, message);
}
}
}
@ -1085,7 +1085,7 @@ pub(super) fn report_invalid_return_type(
expected_ty: Type,
actual_ty: Type,
) {
let Some(builder) = context.lint(&INVALID_RETURN_TYPE) else {
let Some(builder) = context.report_lint(&INVALID_RETURN_TYPE) else {
return;
};
@ -1113,7 +1113,7 @@ pub(super) fn report_implicit_return_type(
range: impl Ranged,
expected_ty: Type,
) {
context.report_lint(
context.report_lint_old(
&INVALID_RETURN_TYPE,
range,
format_args!(
@ -1124,7 +1124,7 @@ pub(super) fn report_implicit_return_type(
}
pub(super) fn report_invalid_type_checking_constant(context: &InferContext, node: AnyNodeRef) {
context.report_lint(
context.report_lint_old(
&INVALID_TYPE_CHECKING_CONSTANT,
node,
format_args!("The name TYPE_CHECKING is reserved for use as a flag; only False can be assigned to it.",),
@ -1137,7 +1137,7 @@ pub(super) fn report_possibly_unresolved_reference(
) {
let ast::ExprName { id, .. } = expr_name_node;
context.report_lint(
context.report_lint_old(
&POSSIBLY_UNRESOLVED_REFERENCE,
expr_name_node,
format_args!("Name `{id}` used when possibly not defined"),
@ -1150,7 +1150,7 @@ pub(super) fn report_possibly_unbound_attribute(
attribute: &str,
object_ty: Type,
) {
context.report_lint(
context.report_lint_old(
&POSSIBLY_UNBOUND_ATTRIBUTE,
target,
format_args!(
@ -1163,7 +1163,7 @@ pub(super) fn report_possibly_unbound_attribute(
pub(super) fn report_unresolved_reference(context: &InferContext, expr_name_node: &ast::ExprName) {
let ast::ExprName { id, .. } = expr_name_node;
context.report_lint(
context.report_lint_old(
&UNRESOLVED_REFERENCE,
expr_name_node,
format_args!("Name `{id}` used when not defined"),
@ -1171,7 +1171,7 @@ pub(super) fn report_unresolved_reference(context: &InferContext, expr_name_node
}
pub(super) fn report_invalid_exception_caught(context: &InferContext, node: &ast::Expr, ty: Type) {
context.report_lint(
context.report_lint_old(
&INVALID_EXCEPTION_CAUGHT,
node,
format_args!(
@ -1183,7 +1183,7 @@ pub(super) fn report_invalid_exception_caught(context: &InferContext, node: &ast
}
pub(crate) fn report_invalid_exception_raised(context: &InferContext, node: &ast::Expr, ty: Type) {
context.report_lint(
context.report_lint_old(
&INVALID_RAISE,
node,
format_args!(
@ -1194,7 +1194,7 @@ pub(crate) fn report_invalid_exception_raised(context: &InferContext, node: &ast
}
pub(crate) fn report_invalid_exception_cause(context: &InferContext, node: &ast::Expr, ty: Type) {
context.report_lint(
context.report_lint_old(
&INVALID_RAISE,
node,
format_args!(
@ -1206,7 +1206,7 @@ pub(crate) fn report_invalid_exception_cause(context: &InferContext, node: &ast:
}
pub(crate) fn report_base_with_incompatible_slots(context: &InferContext, node: &ast::Expr) {
context.report_lint(
context.report_lint_old(
&INCOMPATIBLE_SLOTS,
node,
format_args!("Class base has incompatible `__slots__`"),
@ -1217,7 +1217,7 @@ pub(crate) fn report_invalid_arguments_to_annotated(
context: &InferContext,
subscript: &ast::ExprSubscript,
) {
context.report_lint(
context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -1231,7 +1231,7 @@ pub(crate) fn report_invalid_arguments_to_callable(
context: &InferContext,
subscript: &ast::ExprSubscript,
) {
context.report_lint(
context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(

View File

@ -731,7 +731,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// (1) Check that the class does not have a cyclic definition
if let Some(inheritance_cycle) = class.inheritance_cycle(self.db()) {
if inheritance_cycle.is_participant() {
self.context.report_lint(
self.context.report_lint_old(
&CYCLIC_CLASS_DEFINITION,
class_node,
format_args!(
@ -754,7 +754,7 @@ impl<'db> TypeInferenceBuilder<'db> {
if !base_class.is_final(self.db()) {
continue;
}
self.context.report_lint(
self.context.report_lint_old(
&SUBCLASS_OF_FINAL_CLASS,
&class_node.bases()[i],
format_args!(
@ -772,7 +772,7 @@ impl<'db> TypeInferenceBuilder<'db> {
MroErrorKind::DuplicateBases(duplicates) => {
let base_nodes = class_node.bases();
for (index, duplicate) in duplicates {
self.context.report_lint(
self.context.report_lint_old(
&DUPLICATE_BASE,
&base_nodes[*index],
format_args!("Duplicate base class `{}`", duplicate.name(self.db())),
@ -782,7 +782,7 @@ impl<'db> TypeInferenceBuilder<'db> {
MroErrorKind::InvalidBases(bases) => {
let base_nodes = class_node.bases();
for (index, base_ty) in bases {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_BASE,
&base_nodes[*index],
format_args!(
@ -792,7 +792,7 @@ impl<'db> TypeInferenceBuilder<'db> {
);
}
}
MroErrorKind::UnresolvableMro { bases_list } => self.context.report_lint(
MroErrorKind::UnresolvableMro { bases_list } => self.context.report_lint_old(
&INCONSISTENT_MRO,
class_node,
format_args!(
@ -809,12 +809,12 @@ impl<'db> TypeInferenceBuilder<'db> {
// (4) Check that the class's metaclass can be determined without error.
if let Err(metaclass_error) = class.try_metaclass(self.db()) {
match metaclass_error.reason() {
MetaclassErrorKind::NotCallable(ty) => self.context.report_lint(
MetaclassErrorKind::NotCallable(ty) => self.context.report_lint_old(
&INVALID_METACLASS,
class_node,
format_args!("Metaclass type `{}` is not callable", ty.display(self.db())),
),
MetaclassErrorKind::PartlyNotCallable(ty) => self.context.report_lint(
MetaclassErrorKind::PartlyNotCallable(ty) => self.context.report_lint_old(
&INVALID_METACLASS,
class_node,
format_args!(
@ -836,7 +836,7 @@ impl<'db> TypeInferenceBuilder<'db> {
candidate1_is_base_class,
} => {
if *candidate1_is_base_class {
self.context.report_lint(
self.context.report_lint_old(
&CONFLICTING_METACLASS,
class_node,
format_args!(
@ -851,7 +851,7 @@ impl<'db> TypeInferenceBuilder<'db> {
),
);
} else {
self.context.report_lint(
self.context.report_lint_old(
&CONFLICTING_METACLASS,
class_node,
format_args!(
@ -1005,7 +1005,7 @@ impl<'db> TypeInferenceBuilder<'db> {
_ => return false,
};
self.context.report_lint(
self.context.report_lint_old(
&DIVISION_BY_ZERO,
node,
format_args!(
@ -1033,7 +1033,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// TODO point out the conflicting declarations in the diagnostic?
let symbol_table = self.index.symbol_table(binding.file_scope(self.db()));
let symbol_name = symbol_table.symbol(binding.symbol(self.db())).name();
self.context.report_lint(
self.context.report_lint_old(
&CONFLICTING_DECLARATIONS,
node,
format_args!(
@ -1071,7 +1071,7 @@ impl<'db> TypeInferenceBuilder<'db> {
let ty = if inferred_ty.is_assignable_to(self.db(), ty.inner_type()) {
ty
} else {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_DECLARATION,
node,
format_args!(
@ -1596,7 +1596,7 @@ impl<'db> TypeInferenceBuilder<'db> {
{
DeclaredAndInferredType::AreTheSame(declared_ty)
} else {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_PARAMETER_DEFAULT,
parameter_with_default,
format_args!(
@ -2044,7 +2044,7 @@ impl<'db> TypeInferenceBuilder<'db> {
let bound_or_constraint = match bound.as_deref() {
Some(expr @ ast::Expr::Tuple(ast::ExprTuple { elts, .. })) => {
if elts.len() < 2 {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_VARIABLE_CONSTRAINTS,
expr,
format_args!("TypeVar must have at least two constrained types"),
@ -2363,7 +2363,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// TODO: This is not a very helpful error message, as it does not include the underlying reason
// why the assignment is invalid. This would be a good use case for nested diagnostics.
if emit_diagnostics {
self.context.report_lint(&INVALID_ASSIGNMENT, target, format_args!(
self.context.report_lint_old(&INVALID_ASSIGNMENT, target, format_args!(
"Object of type `{}` is not assignable to attribute `{attribute}` on type `{}`",
value_ty.display(self.db()),
object_ty.display(self.db()),
@ -2383,7 +2383,7 @@ impl<'db> TypeInferenceBuilder<'db> {
} else {
if emit_diagnostics {
// TODO: same here, see above
self.context.report_lint(&INVALID_ASSIGNMENT, target, format_args!(
self.context.report_lint_old(&INVALID_ASSIGNMENT, target, format_args!(
"Object of type `{}` is not assignable to attribute `{attribute}` on type `{}`",
value_ty.display(self.db()),
object_ty.display(self.db()),
@ -2416,7 +2416,7 @@ impl<'db> TypeInferenceBuilder<'db> {
match object_ty.class_member(db, attribute.into()) {
meta_attr @ SymbolAndQualifiers { .. } if meta_attr.is_class_var() => {
if emit_diagnostics {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ATTRIBUTE_ACCESS,
target,
format_args!(
@ -2447,7 +2447,7 @@ impl<'db> TypeInferenceBuilder<'db> {
if !successful_call && emit_diagnostics {
// TODO: Here, it would be nice to emit an additional diagnostic that explains why the call failed
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ASSIGNMENT,
target,
format_args!(
@ -2529,7 +2529,7 @@ impl<'db> TypeInferenceBuilder<'db> {
Ok(_) | Err(CallDunderError::PossiblyUnbound(_)) => true,
Err(CallDunderError::CallError(..)) => {
if emit_diagnostics {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_ATTRIBUTE,
target,
format_args!(
@ -2543,7 +2543,7 @@ impl<'db> TypeInferenceBuilder<'db> {
}
Err(CallDunderError::MethodNotAvailable) => {
if emit_diagnostics {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_ATTRIBUTE,
target,
format_args!(
@ -2584,7 +2584,7 @@ impl<'db> TypeInferenceBuilder<'db> {
if !successful_call && emit_diagnostics {
// TODO: Here, it would be nice to emit an additional diagnostic that explains why the call failed
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ASSIGNMENT,
target,
format_args!(
@ -2662,7 +2662,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// Attribute is declared or bound on instance. Forbid access from the class object
if emit_diagnostics {
if attribute_is_bound_on_instance {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ATTRIBUTE_ACCESS,
target,
format_args!(
@ -2670,7 +2670,7 @@ impl<'db> TypeInferenceBuilder<'db> {
ty = object_ty.display(self.db()),
));
} else {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_ATTRIBUTE,
target,
format_args!(
@ -2703,7 +2703,7 @@ impl<'db> TypeInferenceBuilder<'db> {
false
} else {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_ATTRIBUTE,
target,
format_args!(
@ -2955,7 +2955,7 @@ impl<'db> TypeInferenceBuilder<'db> {
let db = self.db();
let report_unsupported_augmented_op = |ctx: &mut InferContext| {
ctx.report_lint(
ctx.report_lint_old(
&UNSUPPORTED_OPERATOR,
assignment,
format_args!(
@ -3333,7 +3333,7 @@ impl<'db> TypeInferenceBuilder<'db> {
if &alias.name != "*" && boundness == Boundness::PossiblyUnbound {
// TODO: Consider loading _both_ the attribute and any submodule and unioning them
// together if the attribute exists but is possibly-unbound.
self.context.report_lint(
self.context.report_lint_old(
&POSSIBLY_UNBOUND_IMPORT,
AnyNodeRef::Alias(alias),
format_args!("Member `{name}` of module `{module_name}` is possibly unbound",),
@ -3376,7 +3376,7 @@ impl<'db> TypeInferenceBuilder<'db> {
}
if &alias.name != "*" {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_IMPORT,
AnyNodeRef::Alias(alias),
format_args!("Module `{module_name}` has no member `{name}`",),
@ -4107,7 +4107,7 @@ impl<'db> TypeInferenceBuilder<'db> {
if let [Some(revealed_type)] = overload.parameter_types() {
if let Some(builder) = self
.context
.report(DiagnosticId::RevealedType, Severity::Info)
.report_diagnostic(DiagnosticId::RevealedType, Severity::Info)
{
let mut reporter = builder.build("Revealed type");
let span = self.context.span(call_expression);
@ -4124,7 +4124,7 @@ impl<'db> TypeInferenceBuilder<'db> {
if let [Some(actual_ty), Some(asserted_ty)] = overload.parameter_types()
{
if !actual_ty.is_gradual_equivalent_to(self.db(), *asserted_ty) {
self.context.report_lint(
self.context.report_lint_old(
&TYPE_ASSERTION_FAILURE,
call_expression,
format_args!(
@ -4139,7 +4139,7 @@ impl<'db> TypeInferenceBuilder<'db> {
KnownFunction::AssertNever => {
if let [Some(actual_ty)] = overload.parameter_types() {
if !actual_ty.is_equivalent_to(self.db(), Type::Never) {
self.context.report_lint(
self.context.report_lint_old(
&TYPE_ASSERTION_FAILURE,
call_expression,
format_args!(
@ -4178,19 +4178,19 @@ impl<'db> TypeInferenceBuilder<'db> {
.and_then(Type::into_string_literal)
.map(|s| &**s.value(self.db()))
{
self.context.report_lint(
self.context.report_lint_old(
&STATIC_ASSERT_ERROR,
call_expression,
format_args!("Static assertion error: {message}"),
);
} else if *parameter_ty == Type::BooleanLiteral(false) {
self.context.report_lint(
self.context.report_lint_old(
&STATIC_ASSERT_ERROR,
call_expression,
format_args!("Static assertion error: argument evaluates to `False`"),
);
} else if truthiness.is_always_false() {
self.context.report_lint(
self.context.report_lint_old(
&STATIC_ASSERT_ERROR,
call_expression,
format_args!(
@ -4199,7 +4199,7 @@ impl<'db> TypeInferenceBuilder<'db> {
),
);
} else {
self.context.report_lint(
self.context.report_lint_old(
&STATIC_ASSERT_ERROR,
call_expression,
format_args!(
@ -4220,7 +4220,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|| source_type.normalized(db) == casted_type.normalized(db))
&& !source_type.contains_todo(db)
{
self.context.report_lint(
self.context.report_lint_old(
&REDUNDANT_CAST,
call_expression,
format_args!(
@ -4445,7 +4445,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// Still not found? It might be `reveal_type`...
.or_fall_back_to(db, || {
if symbol_name == "reveal_type" {
self.context.report_lint(
self.context.report_lint_old(
&UNDEFINED_REVEAL,
name_node,
format_args!(
@ -4537,7 +4537,7 @@ impl<'db> TypeInferenceBuilder<'db> {
};
if bound_on_instance {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_ATTRIBUTE,
attribute,
format_args!(
@ -4547,7 +4547,7 @@ impl<'db> TypeInferenceBuilder<'db> {
),
);
} else {
self.context.report_lint(
self.context.report_lint_old(
&UNRESOLVED_ATTRIBUTE,
attribute,
format_args!(
@ -4667,7 +4667,7 @@ impl<'db> TypeInferenceBuilder<'db> {
) {
Ok(outcome) => outcome.return_type(self.db()),
Err(e) => {
self.context.report_lint(
self.context.report_lint_old(
&UNSUPPORTED_OPERATOR,
unary,
format_args!(
@ -4695,7 +4695,7 @@ impl<'db> TypeInferenceBuilder<'db> {
self.infer_binary_expression_type(binary.into(), false, left_ty, right_ty, *op)
.unwrap_or_else(|| {
self.context.report_lint(
self.context.report_lint_old(
&UNSUPPORTED_OPERATOR,
binary,
format_args!(
@ -5145,7 +5145,7 @@ impl<'db> TypeInferenceBuilder<'db> {
.infer_binary_type_comparison(left_ty, *op, right_ty, range)
.unwrap_or_else(|error| {
// Handle unsupported operators (diagnostic, `bool`/`Unknown` outcome)
builder.context.report_lint(
builder.context.report_lint_old(
&UNSUPPORTED_OPERATOR,
range,
format_args!(
@ -6031,7 +6031,7 @@ impl<'db> TypeInferenceBuilder<'db> {
) {
Ok(outcome) => return outcome.return_type(self.db()),
Err(err @ CallDunderError::PossiblyUnbound { .. }) => {
self.context.report_lint(
self.context.report_lint_old(
&CALL_POSSIBLY_UNBOUND_METHOD,
value_node,
format_args!(
@ -6043,7 +6043,7 @@ impl<'db> TypeInferenceBuilder<'db> {
return err.fallback_return_type(self.db());
}
Err(CallDunderError::CallError(_, bindings)) => {
self.context.report_lint(
self.context.report_lint_old(
&CALL_NON_CALLABLE,
value_node,
format_args!(
@ -6077,7 +6077,7 @@ impl<'db> TypeInferenceBuilder<'db> {
Symbol::Unbound => {}
Symbol::Type(ty, boundness) => {
if boundness == Boundness::PossiblyUnbound {
self.context.report_lint(
self.context.report_lint_old(
&CALL_POSSIBLY_UNBOUND_METHOD,
value_node,
format_args!(
@ -6093,7 +6093,7 @@ impl<'db> TypeInferenceBuilder<'db> {
) {
Ok(bindings) => return bindings.return_type(self.db()),
Err(CallError(_, bindings)) => {
self.context.report_lint(
self.context.report_lint_old(
&CALL_NON_CALLABLE,
value_node,
format_args!(
@ -6260,7 +6260,7 @@ impl<'db> TypeInferenceBuilder<'db> {
ast::Expr::Starred(starred) => self.infer_starred_expression(starred).into(),
ast::Expr::BytesLiteral(bytes) => {
self.context.report_lint(
self.context.report_lint_old(
&BYTE_STRING_TYPE_ANNOTATION,
bytes,
format_args!("Type expressions cannot use bytes literal"),
@ -6269,7 +6269,7 @@ impl<'db> TypeInferenceBuilder<'db> {
}
ast::Expr::FString(fstring) => {
self.context.report_lint(
self.context.report_lint_old(
&FSTRING_TYPE_ANNOTATION,
fstring,
format_args!("Type expressions cannot use f-strings"),
@ -6343,7 +6343,7 @@ impl<'db> TypeInferenceBuilder<'db> {
known_instance @ (KnownInstanceType::ClassVar | KnownInstanceType::Final),
) => match slice {
ast::Expr::Tuple(..) => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -6444,7 +6444,7 @@ impl<'db> TypeInferenceBuilder<'db> {
message: std::fmt::Arguments,
) -> Type<'db> {
self.context
.report_lint(&INVALID_TYPE_FORM, expression, message);
.report_lint_old(&INVALID_TYPE_FORM, expression, message);
Type::unknown()
}
@ -6881,7 +6881,7 @@ impl<'db> TypeInferenceBuilder<'db> {
}
ast::Expr::Tuple(_) => {
self.infer_type_expression(slice);
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
slice,
format_args!("type[...] must have exactly one type argument"),
@ -6937,7 +6937,7 @@ impl<'db> TypeInferenceBuilder<'db> {
match value_ty {
Type::ClassLiteral(literal) if literal.is_known(self.db(), KnownClass::Any) => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!("Type `typing.Any` expected no type parameter",),
@ -7002,7 +7002,7 @@ impl<'db> TypeInferenceBuilder<'db> {
Ok(ty) => ty,
Err(nodes) => {
for node in nodes {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
node,
format_args!(
@ -7091,7 +7091,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// Type API special forms
KnownInstanceType::Not => match arguments_slice {
ast::Expr::Tuple(_) => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7120,7 +7120,7 @@ impl<'db> TypeInferenceBuilder<'db> {
}
KnownInstanceType::TypeOf => match arguments_slice {
ast::Expr::Tuple(_) => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7138,7 +7138,7 @@ impl<'db> TypeInferenceBuilder<'db> {
},
KnownInstanceType::CallableTypeOf => match arguments_slice {
ast::Expr::Tuple(_) => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7154,7 +7154,7 @@ impl<'db> TypeInferenceBuilder<'db> {
// TODO overloads
let Some(signature) = signatures.iter().flatten().next() else {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
arguments_slice,
format_args!(
@ -7223,7 +7223,7 @@ impl<'db> TypeInferenceBuilder<'db> {
todo_type!("`NotRequired[]` type qualifier")
}
KnownInstanceType::ClassVar | KnownInstanceType::Final => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7262,7 +7262,7 @@ impl<'db> TypeInferenceBuilder<'db> {
| KnownInstanceType::Any
| KnownInstanceType::AlwaysTruthy
| KnownInstanceType::AlwaysFalsy => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7275,7 +7275,7 @@ impl<'db> TypeInferenceBuilder<'db> {
KnownInstanceType::TypingSelf
| KnownInstanceType::TypeAlias
| KnownInstanceType::Unknown => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7286,7 +7286,7 @@ impl<'db> TypeInferenceBuilder<'db> {
Type::unknown()
}
KnownInstanceType::LiteralString => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
subscript,
format_args!(
@ -7432,7 +7432,7 @@ impl<'db> TypeInferenceBuilder<'db> {
}
_ => {
// TODO: Check whether `Expr::Name` is a ParamSpec
self.context.report_lint(
self.context.report_lint_old(
&INVALID_TYPE_FORM,
parameters,
format_args!(

View File

@ -142,7 +142,7 @@ pub(crate) fn parse_string_annotation(
if let Some(string_literal) = string_expr.as_single_part_string() {
let prefix = string_literal.flags.prefix();
if prefix.is_raw() {
context.report_lint(
context.report_lint_old(
&RAW_STRING_TYPE_ANNOTATION,
string_literal,
format_args!("Type expressions cannot use raw string literal"),
@ -152,7 +152,7 @@ pub(crate) fn parse_string_annotation(
} else if &source[string_literal.content_range()] == string_literal.as_str() {
match ruff_python_parser::parse_string_annotation(source.as_str(), string_literal) {
Ok(parsed) => return Some(parsed),
Err(parse_error) => context.report_lint(
Err(parse_error) => context.report_lint_old(
&INVALID_SYNTAX_IN_FORWARD_ANNOTATION,
string_literal,
format_args!("Syntax error in forward annotation: {}", parse_error.error),
@ -161,7 +161,7 @@ pub(crate) fn parse_string_annotation(
} else {
// The raw contents of the string doesn't match the parsed content. This could be the
// case for annotations that contain escape sequences.
context.report_lint(
context.report_lint_old(
&ESCAPE_CHARACTER_IN_FORWARD_ANNOTATION,
string_expr,
format_args!("Type expressions cannot contain escape characters"),
@ -169,7 +169,7 @@ pub(crate) fn parse_string_annotation(
}
} else {
// String is implicitly concatenated.
context.report_lint(
context.report_lint_old(
&IMPLICIT_CONCATENATED_STRING_TYPE_ANNOTATION,
string_expr,
format_args!("Type expressions cannot span multiple string literals"),

View File

@ -130,7 +130,7 @@ impl<'db> Unpacker<'db> {
let length_mismatch = match elts.len().cmp(&tuple_ty_elements.len()) {
Ordering::Less => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ASSIGNMENT,
target,
format_args!(
@ -142,7 +142,7 @@ impl<'db> Unpacker<'db> {
true
}
Ordering::Greater => {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ASSIGNMENT,
target,
format_args!(
@ -246,7 +246,7 @@ impl<'db> Unpacker<'db> {
Cow::Owned(element_types)
} else {
self.context.report_lint(
self.context.report_lint_old(
&INVALID_ASSIGNMENT,
expr,
format_args!(