mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 21:28:21 +00:00
Ignore TRY301
exceptions without except handlers (#4301)
This commit is contained in:
parent
9366eb919d
commit
83536cf87b
3 changed files with 14 additions and 3 deletions
|
@ -45,3 +45,10 @@ def good():
|
|||
logger.exception("a failed")
|
||||
except Exception:
|
||||
logger.exception("something failed")
|
||||
|
||||
|
||||
def fine():
|
||||
try:
|
||||
a = process() # This throws the exception now
|
||||
finally:
|
||||
print("finally")
|
||||
|
|
|
@ -1811,7 +1811,7 @@ where
|
|||
tryceratops::rules::verbose_log_message(self, handlers);
|
||||
}
|
||||
if self.settings.rules.enabled(Rule::RaiseWithinTry) {
|
||||
tryceratops::rules::raise_within_try(self, body);
|
||||
tryceratops::rules::raise_within_try(self, body, handlers);
|
||||
}
|
||||
if self.settings.rules.enabled(Rule::ErrorInsteadOfException) {
|
||||
tryceratops::rules::error_instead_of_exception(self, handlers);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rustpython_parser::ast::{Stmt, StmtKind};
|
||||
use rustpython_parser::ast::{Excepthandler, Stmt, StmtKind};
|
||||
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
@ -72,7 +72,11 @@ where
|
|||
}
|
||||
|
||||
/// TRY301
|
||||
pub fn raise_within_try(checker: &mut Checker, body: &[Stmt]) {
|
||||
pub fn raise_within_try(checker: &mut Checker, body: &[Stmt], handlers: &[Excepthandler]) {
|
||||
if handlers.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let raises = {
|
||||
let mut visitor = RaiseStatementVisitor::default();
|
||||
for stmt in body {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue