Complete documentation for flake8-blind-except and flake8-raise rules (#5143)

## Summary

Completes the documentation for the `flake8-blind-except` and
`flake8-raise` rules.

Related to #2646.

## Test Plan

`python scripts/check_docs_formatted.py`
This commit is contained in:
Tom Kuson 2023-06-17 17:56:27 +01:00 committed by GitHub
parent e1e1d2d341
commit 98920909c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View file

@ -7,6 +7,35 @@ use ruff_python_semantic::analyze::logging;
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for blind `except` clauses.
///
/// ## Why is this bad?
/// Blind exception handling can hide bugs and make debugging difficult. It can
/// also lead to unexpected behavior, such as catching `KeyboardInterrupt` or
/// `SystemExit` exceptions that prevent the user from exiting the program.
///
/// Instead of catching all exceptions, catch only the exceptions you expect.
///
/// ## Example
/// ```python
/// try:
/// foo()
/// except BaseException:
/// ...
/// ```
///
/// Use instead:
/// ```python
/// try:
/// foo()
/// except FileNotFoundError:
/// ...
/// ```
///
/// ## References
/// - [Python documentation: The `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement)
/// - [Python documentation: Exception hierarchy](https://docs.python.org/3/library/exceptions.html#exception-hierarchy)
#[violation]
pub struct BlindExcept {
name: String,

View file

@ -7,6 +7,28 @@ use ruff_python_ast::helpers::match_parens;
use crate::checkers::ast::Checker;
use crate::registry::AsRule;
/// ## What it does
/// Checks for unnecessary parentheses on raised exceptions.
///
/// ## Why is this bad?
/// If no arguments are passed to an exception, parentheses are not required.
/// This is because the `raise` statement accepts either an exception instance
/// or an exception class (which is then implicitly instantiated).
///
/// Removing unnecessary parentheses makes code more readable and idiomatic.
///
/// ## Example
/// ```python
/// raise TypeError()
/// ```
///
/// Use instead:
/// ```python
/// raise TypeError
/// ```
///
/// ## References
/// - [Python documentation: The `raise` statement](https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement)
#[violation]
pub struct UnnecessaryParenOnRaiseException;