mirror of https://github.com/astral-sh/ruff
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
|
|
@ -147,3 +147,10 @@ def f() -> None:
|
||||||
global CONSTANT
|
global CONSTANT
|
||||||
CONSTANT = 1
|
CONSTANT = 1
|
||||||
CONSTANT = 2
|
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.
|
// Lex forwards, to the `:` token.
|
||||||
let following = SimpleTokenizer::starts_at(bound_exception.range.end(), locator.contents())
|
let following = SimpleTokenizer::starts_at(bound_exception.range.end(), locator.contents())
|
||||||
|
.skip_trivia()
|
||||||
.next()
|
.next()
|
||||||
.context("expected the exception name to be followed by a colon")?;
|
.context("expected the exception name to be followed by a colon")?;
|
||||||
debug_assert!(matches!(following.kind, SimpleTokenKind::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`
|
= 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…
Reference in New Issue