Improve magic-value-comparison example in docs (#8111)
Closes https://github.com/astral-sh/ruff/issues/8109.
This commit is contained in:
@@ -22,17 +22,23 @@ use crate::rules::pylint::settings::ConstantType;
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// def calculate_discount(price: float) -> float:
|
||||
/// return price * (1 - 0.2)
|
||||
/// def apply_discount(price: float) -> float:
|
||||
/// if price <= 100:
|
||||
/// return price / 2
|
||||
/// else:
|
||||
/// return price
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// DISCOUNT_RATE = 0.2
|
||||
/// MAX_DISCOUNT = 100
|
||||
///
|
||||
///
|
||||
/// def calculate_discount(price: float) -> float:
|
||||
/// return price * (1 - DISCOUNT_RATE)
|
||||
/// def apply_discount(price: float) -> float:
|
||||
/// if price <= MAX_DISCOUNT:
|
||||
/// return price / 2
|
||||
/// else:
|
||||
/// return price
|
||||
/// ```
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#constants
|
||||
|
||||
Reference in New Issue
Block a user