mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
TRY002: fixup docs (#12683)
This commit is contained in:
parent
0a345dc627
commit
0b4d3ce39b
1 changed files with 7 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
use ruff_python_ast::{self as ast, Expr};
|
use ruff_python_ast::helpers::map_callable;
|
||||||
|
use ruff_python_ast::Expr;
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
@ -7,12 +8,12 @@ use ruff_text_size::Ranged;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
|
|
||||||
/// ## What it does
|
/// ## What it does
|
||||||
/// Checks for code that raises `Exception` directly.
|
/// Checks for code that raises `Exception` or `BaseException` directly.
|
||||||
///
|
///
|
||||||
/// ## Why is this bad?
|
/// ## Why is this bad?
|
||||||
/// Handling such exceptions requires the use of `except Exception`, which
|
/// Handling such exceptions requires the use of `except Exception` or
|
||||||
/// captures _any_ raised exception, including failed assertions,
|
/// `except BaseException`. These will capture almost _any_ raised exception,
|
||||||
/// division by zero, and more.
|
/// including failed assertions, division by zero, and more.
|
||||||
///
|
///
|
||||||
/// Prefer to raise your own exception, or a more specific built-in
|
/// Prefer to raise your own exception, or a more specific built-in
|
||||||
/// exception, so that you can avoid over-capturing exceptions that you
|
/// exception, so that you can avoid over-capturing exceptions that you
|
||||||
|
@ -63,15 +64,9 @@ impl Violation for RaiseVanillaClass {
|
||||||
|
|
||||||
/// TRY002
|
/// TRY002
|
||||||
pub(crate) fn raise_vanilla_class(checker: &mut Checker, expr: &Expr) {
|
pub(crate) fn raise_vanilla_class(checker: &mut Checker, expr: &Expr) {
|
||||||
let node = if let Expr::Call(ast::ExprCall { func, .. }) = expr {
|
|
||||||
func
|
|
||||||
} else {
|
|
||||||
expr
|
|
||||||
};
|
|
||||||
|
|
||||||
if checker
|
if checker
|
||||||
.semantic()
|
.semantic()
|
||||||
.resolve_qualified_name(node)
|
.resolve_qualified_name(map_callable(expr))
|
||||||
.is_some_and(|qualified_name| {
|
.is_some_and(|qualified_name| {
|
||||||
matches!(
|
matches!(
|
||||||
qualified_name.segments(),
|
qualified_name.segments(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue