From c6d2ac91005d3e68cafd791ed9c6ef3fee4bf50c Mon Sep 17 00:00:00 2001 From: thomas girod Date: Mon, 8 Jul 2024 12:34:06 +0200 Subject: [PATCH] ruff rule B --- core/middleware.py | 2 +- counter/views.py | 2 +- .../management/commands/generate_galaxy_test_data.py | 4 +++- galaxy/management/commands/rule_galaxy.py | 4 +++- galaxy/models.py | 2 +- pyproject.toml | 10 ++++++---- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/middleware.py b/core/middleware.py index 9e08fa58..5f5c945b 100644 --- a/core/middleware.py +++ b/core/middleware.py @@ -68,5 +68,5 @@ class SignalRequestMiddleware: self.get_response = get_response def __call__(self, request): - setattr(_threadlocal, "request", request) + _threadlocal.request = request return self.get_response(request) diff --git a/counter/views.py b/counter/views.py index 08b88c00..7587df2f 100644 --- a/counter/views.py +++ b/counter/views.py @@ -434,7 +434,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): def sum_basket(self, request): total = 0 - for pid, infos in request.session["basket"].items(): + for infos in request.session["basket"].values(): total += infos["price"] * infos["qty"] return total / 100 diff --git a/galaxy/management/commands/generate_galaxy_test_data.py b/galaxy/management/commands/generate_galaxy_test_data.py index 023145e5..25437def 100644 --- a/galaxy/management/commands/generate_galaxy_test_data.py +++ b/galaxy/management/commands/generate_galaxy_test_data.py @@ -72,7 +72,9 @@ class Command(BaseCommand): def handle(self, *args, **options): self.logger = logging.getLogger("main") if options["verbosity"] < 0 or 2 < options["verbosity"]: - warnings.warn("verbosity level should be between 0 and 2 included") + warnings.warn( + "verbosity level should be between 0 and 2 included", stacklevel=2 + ) if options["verbosity"] == 2: self.logger.setLevel(logging.DEBUG) diff --git a/galaxy/management/commands/rule_galaxy.py b/galaxy/management/commands/rule_galaxy.py index a204cd98..90510b3f 100644 --- a/galaxy/management/commands/rule_galaxy.py +++ b/galaxy/management/commands/rule_galaxy.py @@ -41,7 +41,9 @@ class Command(BaseCommand): def handle(self, *args, **options): logger = logging.getLogger("main") if options["verbosity"] < 0 or 2 < options["verbosity"]: - warnings.warn("verbosity level should be between 0 and 2 included") + warnings.warn( + "verbosity level should be between 0 and 2 included", stacklevel=2 + ) if options["verbosity"] == 2: logger.setLevel(logging.DEBUG) diff --git a/galaxy/models.py b/galaxy/models.py index d477fad6..0a4674b0 100644 --- a/galaxy/models.py +++ b/galaxy/models.py @@ -86,7 +86,7 @@ def current_star(self) -> Optional[GalaxyStar]: # Adding a shortcut to User class for getting its star belonging to the latest ruled Galaxy -setattr(User, "current_star", current_star) +User.current_star = current_star class GalaxyLane(models.Model): diff --git a/pyproject.toml b/pyproject.toml index a690bfea..07f823dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,13 +71,15 @@ version = "1.4.25" [tool.ruff.lint] select = [ - "I", # isort - "B", "A", # shadowing of Python builtins - "F401", # unused import + "B", + "C4", # use comprehensions when possible + "I", # isort "DJ", # django-specific rules, + "F401", # unused import + "FBT", # boolean trap "UP008", # Use super() instead of super(__class__, self) - "UP009" # utf-8 encoding declaration is unnecessary + "UP009", # utf-8 encoding declaration is unnecessary ] ignore = [