From ce0d2e080b9cedca6ae6f66647b2380fc58714a7 Mon Sep 17 00:00:00 2001 From: "deepsource-dev-autofix[bot]" <61578317+deepsource-dev-autofix[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 07:04:49 +0000 Subject: [PATCH 1/2] refactor: replace multiple `==` checks with `in` To check if a variable is equal to one of many values, combine the values into a tuple and check if the variable is contained `in` it instead of checking for equality against each of the values. This is faster, less verbose, and more readable. --- demo_code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo_code.py b/demo_code.py index 301fcff83..ba6995d5c 100644 --- a/demo_code.py +++ b/demo_code.py @@ -111,7 +111,7 @@ def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz): def check(x): - if x == 1 or x == 2 or x == 3: + if x in (1, 2, 3): print("Yes") elif x != 2 or x != 3: print("also true") @@ -122,7 +122,7 @@ def check(x): elif x == 10 or x == 20 or x == 30 and x == 40: print("Sweet!") - elif x == 10 or x == 20 or x == 30: + elif x in (10, 20, 30): print("Why even?") From 80c1f7a5fe028b072f7d22d51ab72092afd0be9d Mon Sep 17 00:00:00 2001 From: "deepsource-dev-autofix[bot]" <61578317+deepsource-dev-autofix[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 07:04:58 +0000 Subject: [PATCH 2/2] style: format code with Ruff Formatter This commit fixes the style issues introduced in ce0d2e0 according to the output from Ruff Formatter. Details: https://github.com/parths-test-org/demo-python/pull/193 --- demo_code.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/demo_code.py b/demo_code.py index ba6995d5c..4098d37c4 100644 --- a/demo_code.py +++ b/demo_code.py @@ -8,19 +8,19 @@ # from django.db.models.expressions import RawSQL -AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&c2" +AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&c2" class BaseNumberGenerator: """Declare a method -- `get_number`.""" - def __init__(self ): - self.limits = (1, 10) + def __init__(self): + self.limits = (1, 10) - def get_number(self , min_max): - raise NotImplementedError + def get_number(self, min_max): + raise NotImplementedError - def smethod( ): + def smethod(): """static method-to-be""" smethod = staticmethod(smethod)