Improve magic-value-comparison example in docs (#8111)

Closes https://github.com/astral-sh/ruff/issues/8109.
This commit is contained in:
Charlie Marsh 2023-10-21 19:05:43 -04:00 committed by GitHub
parent 2414f23abb
commit 00fd324c6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,17 +22,23 @@ use crate::rules::pylint::settings::ConstantType;
/// ///
/// ## Example /// ## Example
/// ```python /// ```python
/// def calculate_discount(price: float) -> float: /// def apply_discount(price: float) -> float:
/// return price * (1 - 0.2) /// if price <= 100:
/// return price / 2
/// else:
/// return price
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
/// ```python /// ```python
/// DISCOUNT_RATE = 0.2 /// MAX_DISCOUNT = 100
/// ///
/// ///
/// def calculate_discount(price: float) -> float: /// def apply_discount(price: float) -> float:
/// return price * (1 - DISCOUNT_RATE) /// if price <= MAX_DISCOUNT:
/// return price / 2
/// else:
/// return price
/// ``` /// ```
/// ///
/// [PEP 8]: https://peps.python.org/pep-0008/#constants /// [PEP 8]: https://peps.python.org/pep-0008/#constants