mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 10:01:15 +00:00
Remove exception-handler lexing from unused-bound-exception
fix (#5851)
## Summary The motivation here is that it will make this rule easier to rewrite as a deferred check. Right now, we can't run this rule in the deferred phase, because it depends on the `except_handler` to power its autofix. Instead of lexing the `except_handler`, we can use the `SimpleTokenizer` from the formatter, and just lex forwards and backwards. For context, this rule detects the unused `e` in: ```python try: pass except ValueError as e: pass ```
This commit is contained in:
parent
41da52a61b
commit
4204fc002d
32 changed files with 125 additions and 112 deletions
|
@ -7,14 +7,16 @@ use rustpython_parser::ast::{Expr, ExprIfExp, ExprSlice, Ranged};
|
|||
use ruff_python_ast::node::{AnyNodeRef, AstNode};
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
use ruff_python_ast::whitespace;
|
||||
use ruff_python_whitespace::{PythonWhitespace, UniversalNewlines};
|
||||
use ruff_python_whitespace::{
|
||||
first_non_trivia_token_rev, PythonWhitespace, SimpleTokenizer, Token, TokenKind,
|
||||
UniversalNewlines,
|
||||
};
|
||||
|
||||
use crate::comments::visitor::{CommentPlacement, DecoratedComment};
|
||||
use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
|
||||
use crate::other::arguments::{
|
||||
assign_argument_separator_comment_placement, find_argument_separators,
|
||||
};
|
||||
use crate::trivia::{first_non_trivia_token_rev, SimpleTokenizer, Token, TokenKind};
|
||||
|
||||
/// Implements the custom comment placement logic.
|
||||
pub(super) fn place_comment<'a>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue