mirror of https://github.com/astral-sh/ruff
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
|
|
@ -59,11 +59,8 @@ impl<'db> InferContext<'db> {
|
||||||
self.db
|
self.db
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extend<T>(&mut self, other: &T)
|
pub(crate) fn extend(&mut self, other: &TypeCheckDiagnostics) {
|
||||||
where
|
self.diagnostics.get_mut().extend(other);
|
||||||
T: WithDiagnostics,
|
|
||||||
{
|
|
||||||
self.diagnostics.get_mut().extend(other.diagnostics());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reports a lint located at `ranged`.
|
/// 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.
|
/// The inference is known to be in an `@no_type_check` decorated function.
|
||||||
Yes,
|
Yes,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait WithDiagnostics {
|
|
||||||
fn diagnostics(&self) -> &TypeCheckDiagnostics;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ use crate::util::subscript::{PyIndex, PySlice};
|
||||||
use crate::Db;
|
use crate::Db;
|
||||||
|
|
||||||
use super::class_base::ClassBase;
|
use super::class_base::ClassBase;
|
||||||
use super::context::{InNoTypeCheck, InferContext, WithDiagnostics};
|
use super::context::{InNoTypeCheck, InferContext};
|
||||||
use super::diagnostic::{
|
use super::diagnostic::{
|
||||||
report_index_out_of_bounds, report_invalid_exception_caught, report_invalid_exception_cause,
|
report_index_out_of_bounds, report_invalid_exception_caught, report_invalid_exception_cause,
|
||||||
report_invalid_exception_raised, report_invalid_type_checking_constant,
|
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.
|
/// Whether the intersection type is on the left or right side of the comparison.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum IntersectionOn {
|
enum IntersectionOn {
|
||||||
|
|
@ -567,7 +561,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
.extend(inference.declarations.iter());
|
.extend(inference.declarations.iter());
|
||||||
self.types.expressions.extend(inference.expressions.iter());
|
self.types.expressions.extend(inference.expressions.iter());
|
||||||
self.types.deferred.extend(inference.deferred.iter());
|
self.types.deferred.extend(inference.deferred.iter());
|
||||||
self.context.extend(inference);
|
self.context.extend(inference.diagnostics());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file(&self) -> File {
|
fn file(&self) -> File {
|
||||||
|
|
@ -1863,7 +1857,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
let unpacked = infer_unpack_types(self.db(), unpack);
|
let unpacked = infer_unpack_types(self.db(), unpack);
|
||||||
let name_ast_id = name.scoped_expression_id(self.db(), self.scope());
|
let name_ast_id = name.scoped_expression_id(self.db(), self.scope());
|
||||||
if unpack_position == UnpackPosition::First {
|
if unpack_position == UnpackPosition::First {
|
||||||
self.context.extend(unpacked);
|
self.context.extend(unpacked.diagnostics());
|
||||||
}
|
}
|
||||||
unpacked.expression_type(name_ast_id)
|
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
|
// Only copy the diagnostics if this is the first assignment to avoid duplicating the
|
||||||
// unpack assignments.
|
// unpack assignments.
|
||||||
if unpack_position == UnpackPosition::First {
|
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());
|
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) => {
|
TargetKind::Sequence(unpack_position, unpack) => {
|
||||||
let unpacked = infer_unpack_types(self.db(), unpack);
|
let unpacked = infer_unpack_types(self.db(), unpack);
|
||||||
if unpack_position == UnpackPosition::First {
|
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());
|
let name_ast_id = name.scoped_expression_id(self.db(), self.scope());
|
||||||
unpacked.expression_type(name_ast_id)
|
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::unpack::{UnpackKind, UnpackValue};
|
||||||
use crate::Db;
|
use crate::Db;
|
||||||
|
|
||||||
use super::context::{InferContext, WithDiagnostics};
|
use super::context::InferContext;
|
||||||
use super::diagnostic::INVALID_ASSIGNMENT;
|
use super::diagnostic::INVALID_ASSIGNMENT;
|
||||||
use super::{TupleType, UnionType};
|
use super::{TupleType, UnionType};
|
||||||
|
|
||||||
|
|
@ -283,10 +283,9 @@ impl<'db> UnpackResult<'db> {
|
||||||
pub(crate) fn expression_type(&self, expr_id: ScopedExpressionId) -> Type<'db> {
|
pub(crate) fn expression_type(&self, expr_id: ScopedExpressionId) -> Type<'db> {
|
||||||
self.targets[&expr_id]
|
self.targets[&expr_id]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl WithDiagnostics for UnpackResult<'_> {
|
/// Returns the diagnostics in this unpacking assignment.
|
||||||
fn diagnostics(&self) -> &TypeCheckDiagnostics {
|
pub(crate) fn diagnostics(&self) -> &TypeCheckDiagnostics {
|
||||||
&self.diagnostics
|
&self.diagnostics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue