From 00fd324c6f1089c83fe5b14c5e1caaebcc1efdd3 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 21 Oct 2023 19:05:43 -0400 Subject: [PATCH] Improve `magic-value-comparison` example in docs (#8111) Closes https://github.com/astral-sh/ruff/issues/8109. --- .../rules/pylint/rules/magic_value_comparison.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs index 81e24c4ca603a..2bc7999066cbf 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs @@ -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