mirror of
https://github.com/astral-sh/ruff
synced 2026-01-09 07:34:06 -05:00
Move unused deletion tracking to deferred analysis (#5852)
## Summary This PR moves the "unused exception" rule out of the visitor and into a deferred check. When we can base rules solely on the semantic model, we probably should, as it greatly simplifies the `Checker` itself.
This commit is contained in:
@@ -5,6 +5,7 @@ use ruff_text_size::TextRange;
|
||||
use rustpython_parser::ast::Ranged;
|
||||
|
||||
use ruff_index::{newtype_index, IndexSlice, IndexVec};
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
use crate::context::ExecutionContext;
|
||||
use crate::model::SemanticModel;
|
||||
@@ -163,6 +164,11 @@ impl<'a> Binding<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the name of the binding (e.g., `x` in `x = 1`).
|
||||
pub fn name<'b>(&self, locator: &'b Locator) -> &'b str {
|
||||
locator.slice(self.range)
|
||||
}
|
||||
|
||||
/// Returns the range of the binding's parent.
|
||||
pub fn parent_range(&self, semantic: &SemanticModel) -> Option<TextRange> {
|
||||
self.source
|
||||
@@ -417,7 +423,16 @@ pub enum BindingKind<'a> {
|
||||
/// ```
|
||||
Deletion,
|
||||
|
||||
/// A binding to unbind the local variable, like `x` in:
|
||||
/// A binding to bind an exception to a local variable, like `x` in:
|
||||
/// ```python
|
||||
/// try:
|
||||
/// ...
|
||||
/// except Exception as x:
|
||||
/// ...
|
||||
/// ```
|
||||
BoundException,
|
||||
|
||||
/// A binding to unbind a bound local exception, like `x` in:
|
||||
/// ```python
|
||||
/// try:
|
||||
/// ...
|
||||
@@ -428,7 +443,6 @@ pub enum BindingKind<'a> {
|
||||
/// After the `except` block, `x` is unbound, despite the lack
|
||||
/// of an explicit `del` statement.
|
||||
///
|
||||
///
|
||||
/// Stores the ID of the binding that was shadowed in the enclosing
|
||||
/// scope, if any.
|
||||
UnboundException(Option<BindingId>),
|
||||
|
||||
Reference in New Issue
Block a user