mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Skip trivia when searching for named exception (#6218)
Closes https://github.com/astral-sh/ruff/issues/6213.
This commit is contained in:
parent
38b5726948
commit
ff9ebbaa5f
3 changed files with 26 additions and 0 deletions
|
@ -147,3 +147,10 @@ def f() -> None:
|
|||
global CONSTANT
|
||||
CONSTANT = 1
|
||||
CONSTANT = 2
|
||||
|
||||
|
||||
def f() -> None:
|
||||
try:
|
||||
print("hello")
|
||||
except A as e :
|
||||
print("oh no!")
|
||||
|
|
|
@ -115,6 +115,7 @@ pub(crate) fn remove_exception_handler_assignment(
|
|||
|
||||
// Lex forwards, to the `:` token.
|
||||
let following = SimpleTokenizer::starts_at(bound_exception.range.end(), locator.contents())
|
||||
.skip_trivia()
|
||||
.next()
|
||||
.context("expected the exception name to be followed by a colon")?;
|
||||
debug_assert!(matches!(following.kind, SimpleTokenKind::Colon));
|
||||
|
|
|
@ -584,4 +584,22 @@ F841_3.py:139:17: F841 Local variable `x` is assigned to but never used
|
|||
|
|
||||
= help: Remove assignment to unused variable `x`
|
||||
|
||||
F841_3.py:155:17: F841 [*] Local variable `e` is assigned to but never used
|
||||
|
|
||||
153 | try:
|
||||
154 | print("hello")
|
||||
155 | except A as e :
|
||||
| ^ F841
|
||||
156 | print("oh no!")
|
||||
|
|
||||
= help: Remove assignment to unused variable `e`
|
||||
|
||||
ℹ Fix
|
||||
152 152 | def f() -> None:
|
||||
153 153 | try:
|
||||
154 154 | print("hello")
|
||||
155 |- except A as e :
|
||||
155 |+ except A:
|
||||
156 156 | print("oh no!")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue