[docs] Add some docs for `flake8-simplify` (#3027)

This commit is contained in:
Jeremy Goh 2023-02-19 22:26:56 +08:00 committed by GitHub
parent e53652779d
commit 13281cd9ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 0 deletions

View File

@ -13,6 +13,32 @@ use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation; use crate::violation::AlwaysAutofixableViolation;
define_violation!( define_violation!(
/// ## What it does
/// Checks for multiple `isinstance` calls on the same target.
///
/// ## Why is this bad?
/// To check if an object is an instance of any one of multiple types
/// or classes, it is unnecessary to use multiple `isinstance` calls, as
/// the second argument of the `isinstance` built-in function accepts a
/// tuple of types and classes.
///
/// Using a single `isinstance` call implements the same behavior with more
/// concise code and clearer intent.
///
/// ## Example
/// ```python
/// if isinstance(obj, int) or isinstance(obj, float):
/// pass
/// ```
///
/// Use instead:
/// ```python
/// if isinstance(obj, (int, float)):
/// pass
///
/// ## References
/// * [Python: "isinstance"](https://docs.python.org/3/library/functions.html#isinstance)
/// ```
pub struct DuplicateIsinstanceCall { pub struct DuplicateIsinstanceCall {
pub name: String, pub name: String,
} }

View File

@ -12,6 +12,33 @@ use crate::violation::{AutofixKind, Availability, Violation};
use super::fix_with; use super::fix_with;
define_violation!( define_violation!(
/// ## What it does
/// Checks for the unnecessary nesting of multiple consecutive context
/// managers.
///
/// ## Why is this bad?
/// In Python 3, a single `with` block can include multiple context
/// managers.
///
/// Combining multiple context managers into a single `with` statement
/// will minimize the indentation depth of the code, making it more
/// readable.
///
/// ## Example
/// ```python
/// with A() as a:
/// with B() as b:
/// pass
/// ```
///
/// Use instead:
/// ```python
/// with A() as a, B() as b:
/// pass
/// ```
///
/// ## References
/// * [Python: "The with statement"](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement)
pub struct MultipleWithStatements { pub struct MultipleWithStatements {
pub fixable: bool, pub fixable: bool,
} }