mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-15 22:14:44 +00:00
red_knot_python_semantic: remove WithDiagnostic trait
I did this mostly because it wasn't buying us much, and I'm trying to simplify the public API of the types I'd like to refactor in order to make the refactor simpler. If we really want something like this, we can re-add it later.
This commit is contained in:
parent
a953373892
commit
a8a18e7171
3 changed files with 10 additions and 24 deletions
|
|
@ -59,11 +59,8 @@ impl<'db> InferContext<'db> {
|
|||
self.db
|
||||
}
|
||||
|
||||
pub(crate) fn extend<T>(&mut self, other: &T)
|
||||
where
|
||||
T: WithDiagnostics,
|
||||
{
|
||||
self.diagnostics.get_mut().extend(other.diagnostics());
|
||||
pub(crate) fn extend(&mut self, other: &TypeCheckDiagnostics) {
|
||||
self.diagnostics.get_mut().extend(other);
|
||||
}
|
||||
|
||||
/// Reports a lint located at `ranged`.
|
||||
|
|
@ -223,7 +220,3 @@ pub(crate) enum InNoTypeCheck {
|
|||
/// The inference is known to be in an `@no_type_check` decorated function.
|
||||
Yes,
|
||||
}
|
||||
|
||||
pub(crate) trait WithDiagnostics {
|
||||
fn diagnostics(&self) -> &TypeCheckDiagnostics;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ use crate::util::subscript::{PyIndex, PySlice};
|
|||
use crate::Db;
|
||||
|
||||
use super::class_base::ClassBase;
|
||||
use super::context::{InNoTypeCheck, InferContext, WithDiagnostics};
|
||||
use super::context::{InNoTypeCheck, InferContext};
|
||||
use super::diagnostic::{
|
||||
report_index_out_of_bounds, report_invalid_exception_caught, report_invalid_exception_cause,
|
||||
report_invalid_exception_raised, report_invalid_type_checking_constant,
|
||||
|
|
@ -439,12 +439,6 @@ impl<'db> TypeInference<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
impl WithDiagnostics for TypeInference<'_> {
|
||||
fn diagnostics(&self) -> &TypeCheckDiagnostics {
|
||||
&self.diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the intersection type is on the left or right side of the comparison.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum IntersectionOn {
|
||||
|
|
@ -567,7 +561,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
.extend(inference.declarations.iter());
|
||||
self.types.expressions.extend(inference.expressions.iter());
|
||||
self.types.deferred.extend(inference.deferred.iter());
|
||||
self.context.extend(inference);
|
||||
self.context.extend(inference.diagnostics());
|
||||
}
|
||||
|
||||
fn file(&self) -> File {
|
||||
|
|
@ -1863,7 +1857,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
let unpacked = infer_unpack_types(self.db(), unpack);
|
||||
let name_ast_id = name.scoped_expression_id(self.db(), self.scope());
|
||||
if unpack_position == UnpackPosition::First {
|
||||
self.context.extend(unpacked);
|
||||
self.context.extend(unpacked.diagnostics());
|
||||
}
|
||||
unpacked.expression_type(name_ast_id)
|
||||
}
|
||||
|
|
@ -2673,7 +2667,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
// Only copy the diagnostics if this is the first assignment to avoid duplicating the
|
||||
// unpack assignments.
|
||||
if unpack_position == UnpackPosition::First {
|
||||
self.context.extend(unpacked);
|
||||
self.context.extend(unpacked.diagnostics());
|
||||
}
|
||||
|
||||
let name_ast_id = name.scoped_expression_id(self.db(), self.scope());
|
||||
|
|
@ -2973,7 +2967,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
TargetKind::Sequence(unpack_position, unpack) => {
|
||||
let unpacked = infer_unpack_types(self.db(), unpack);
|
||||
if unpack_position == UnpackPosition::First {
|
||||
self.context.extend(unpacked);
|
||||
self.context.extend(unpacked.diagnostics());
|
||||
}
|
||||
let name_ast_id = name.scoped_expression_id(self.db(), self.scope());
|
||||
unpacked.expression_type(name_ast_id)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::types::{infer_expression_types, todo_type, Type, TypeCheckDiagnostics
|
|||
use crate::unpack::{UnpackKind, UnpackValue};
|
||||
use crate::Db;
|
||||
|
||||
use super::context::{InferContext, WithDiagnostics};
|
||||
use super::context::InferContext;
|
||||
use super::diagnostic::INVALID_ASSIGNMENT;
|
||||
use super::{TupleType, UnionType};
|
||||
|
||||
|
|
@ -283,10 +283,9 @@ impl<'db> UnpackResult<'db> {
|
|||
pub(crate) fn expression_type(&self, expr_id: ScopedExpressionId) -> Type<'db> {
|
||||
self.targets[&expr_id]
|
||||
}
|
||||
}
|
||||
|
||||
impl WithDiagnostics for UnpackResult<'_> {
|
||||
fn diagnostics(&self) -> &TypeCheckDiagnostics {
|
||||
/// Returns the diagnostics in this unpacking assignment.
|
||||
pub(crate) fn diagnostics(&self) -> &TypeCheckDiagnostics {
|
||||
&self.diagnostics
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue