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
/// ```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