mirror of https://github.com/astral-sh/ruff
[docs] Add some docs for `flake8-simplify` (#3027)
This commit is contained in:
parent
e53652779d
commit
13281cd9ca
|
|
@ -13,6 +13,32 @@ use crate::registry::Diagnostic;
|
|||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
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 name: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,33 @@ use crate::violation::{AutofixKind, Availability, Violation};
|
|||
use super::fix_with;
|
||||
|
||||
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 fixable: bool,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue