mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +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")
|
logger.exception("a failed")
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("something failed")
|
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);
|
tryceratops::rules::verbose_log_message(self, handlers);
|
||||||
}
|
}
|
||||||
if self.settings.rules.enabled(Rule::RaiseWithinTry) {
|
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) {
|
if self.settings.rules.enabled(Rule::ErrorInsteadOfException) {
|
||||||
tryceratops::rules::error_instead_of_exception(self, handlers);
|
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_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
@ -72,7 +72,11 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TRY301
|
/// 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 raises = {
|
||||||
let mut visitor = RaiseStatementVisitor::default();
|
let mut visitor = RaiseStatementVisitor::default();
|
||||||
for stmt in body {
|
for stmt in body {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue