diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2906eb95e6..0145d26fa9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -14,11 +14,11 @@ repos: - id: check-toml - id: debug-statements - repo: https://github.com/scop/pre-commit-shfmt - rev: v3.11.0-1 + rev: v3.12.0-2 hooks: - id: shfmt - repo: https://github.com/adrienverge/yamllint.git - rev: v1.37.0 + rev: v1.37.1 hooks: - id: yamllint args: [--format, parsable, -d, relaxed] @@ -47,7 +47,7 @@ repos: - "config/keycloak/*" additional_dependencies: ["gibberish-detector"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.11.7" + rev: "v0.14.7" hooks: - id: ruff-format - id: ruff @@ -55,12 +55,12 @@ repos: - --extend-ignore=D1 - --fix - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.10.0.1 + rev: v0.11.0.1 hooks: - id: shellcheck args: ["--severity=warning"] - repo: https://github.com/rhysd/actionlint - rev: v1.7.7 + rev: v1.7.9 hooks: - id: actionlint name: actionlint diff --git a/authentication/middleware.py b/authentication/middleware.py index 0bd31ea87a..62e79f6b73 100644 --- a/authentication/middleware.py +++ b/authentication/middleware.py @@ -22,14 +22,14 @@ def process_exception(self, request, exception): if strategy is None or self.raise_exception(request, exception): return None - if isinstance(exception, SocialAuthBaseException): # noqa: RET503 + if isinstance(exception, SocialAuthBaseException): backend = getattr(request, "backend", None) backend_name = getattr(backend, "name", "unknown-backend") message = self.get_message(request, exception) url = self.get_redirect_uri(request, exception) - if url: # noqa: RET503 + if url: url += ( ("?" in url and "&") or "?" ) + f"message={quote(message)}&backend={backend_name}" diff --git a/cms/models.py b/cms/models.py index fff0b4671f..dbf3b3e408 100644 --- a/cms/models.py +++ b/cms/models.py @@ -102,7 +102,7 @@ class Meta: def video_player_config(self): """Get configuration for video player""" - if self.video_url: # noqa: RET503 + if self.video_url: config = {"techOrder": ["html5"], "sources": [{"src": self.video_url}]} try: embed = get_embed(self.video_url) diff --git a/cms/tasks.py b/cms/tasks.py index f32dca63f9..009412bc9a 100644 --- a/cms/tasks.py +++ b/cms/tasks.py @@ -76,7 +76,7 @@ def queue_fastly_purge_url(page_id): logger.info("Purge request processed OK.") return True - logger.error("Purge request failed.") # noqa: RET503 + logger.error("Purge request failed.") @app.task() @@ -96,7 +96,7 @@ def queue_fastly_full_purge(): logger.info("Purge request processed OK.") return True - logger.error("Purge request failed.") # noqa: RET503 + logger.error("Purge request failed.") @app.task diff --git a/courses/serializers/v1/base.py b/courses/serializers/v1/base.py index c654cada08..c2918aa392 100644 --- a/courses/serializers/v1/base.py +++ b/courses/serializers/v1/base.py @@ -1,7 +1,5 @@ from __future__ import annotations -from typing import Optional - from drf_spectacular.utils import extend_schema_field from rest_framework import serializers @@ -47,7 +45,7 @@ class BaseCourseRunSerializer(serializers.ModelSerializer): course_number = serializers.SerializerMethodField() courseware_url = serializers.SerializerMethodField() - def get_courseware_url(self, instance) -> Optional[str]: + def get_courseware_url(self, instance) -> str | None: """Get the courseware URL""" return instance.courseware_url diff --git a/courses/views/v1/__init__.py b/courses/views/v1/__init__.py index 902ae35bdf..136d0bb980 100644 --- a/courses/views/v1/__init__.py +++ b/courses/views/v1/__init__.py @@ -269,7 +269,7 @@ def get_serializer_context(self): def _validate_enrollment_post_request( request: Request, -) -> Union[Tuple[Optional[HttpResponse], None, None], Tuple[None, User, CourseRun]]: # noqa: UP006 +) -> Union[Tuple[HttpResponse | None, None, None], Tuple[None, User, CourseRun]]: # noqa: UP006 """ Validates a request to create an enrollment. Returns a response if validation fails, or a user and course run if validation succeeds. diff --git a/ecommerce/models.py b/ecommerce/models.py index c51fe4b419..9d3e993c13 100644 --- a/ecommerce/models.py +++ b/ecommerce/models.py @@ -4,7 +4,7 @@ import uuid from datetime import datetime from decimal import Decimal -from typing import List, Optional # noqa: UP035 +from typing import List # noqa: UP035 import pytz import reversion @@ -804,7 +804,7 @@ def create_from_basket(cls, basket: Basket): @classmethod def create_from_product( - cls, product: Product, user: User, discount: Optional[Discount] = None + cls, product: Product, user: User, discount: Discount | None = None ): """ Creates a new pending order from a product diff --git a/flexiblepricing/serializers.py b/flexiblepricing/serializers.py index 8f80ff78eb..28c928d9ec 100644 --- a/flexiblepricing/serializers.py +++ b/flexiblepricing/serializers.py @@ -207,7 +207,7 @@ def get_courseware_object(self, instance): program_content_type = ContentType.objects.get( app_label="courses", model="program" ).id - if instance["courseware_content_type"] == course_content_type: # noqa: RET503 + if instance["courseware_content_type"] == course_content_type: return BaseCourseSerializer( Course.objects.filter(id=instance["courseware_object_id"]).first() ).data diff --git a/hubspot_sync/api.py b/hubspot_sync/api.py index 62fa78aee7..a0edf1425c 100644 --- a/hubspot_sync/api.py +++ b/hubspot_sync/api.py @@ -1231,7 +1231,7 @@ def get_hubspot_id_for_object( # noqa: C901 serialized_product["name"], raise_count_error=raise_error, ) - if hubspot_obj and hubspot_obj.id: # noqa: RET503 + if hubspot_obj and hubspot_obj.id: try: HubspotObject.objects.update_or_create( object_id=obj.id, diff --git a/hubspot_sync/serializers.py b/hubspot_sync/serializers.py index 3cc6fe3c1a..241e69e3e7 100644 --- a/hubspot_sync/serializers.py +++ b/hubspot_sync/serializers.py @@ -103,13 +103,13 @@ def get_status(self, instance): def get_product_id(self, instance): """Return the product version text_id""" product = self._get_product(instance) - if product: # noqa: RET503 + if product: return product.purchasable_object.readable_id def get_price(self, instance): """Get the product version price""" product = self._get_product(instance) - if product: # noqa: RET503 + if product: return format_decimal(product.price) class Meta: @@ -182,13 +182,13 @@ def get_dealstage(self, instance): def get_closedate(self, instance): """Return the updated_on date (as a timestamp in milliseconds) if fulfilled""" - if instance.state == models.OrderStatus.FULFILLED: # noqa: RET503 + if instance.state == models.OrderStatus.FULFILLED: return int(instance.updated_on.timestamp() * 1000) def get_discount_type(self, instance): """Get the discount type of the applied coupon""" discount = self._get_discount(instance) - if discount: # noqa: RET503 + if discount: return discount.discount_type def get_amount(self, instance): @@ -230,7 +230,7 @@ def get_discount_percent(self, instance): def get_coupon_code(self, instance): """Get the coupon code used for the order if any""" discount = self._get_discount(instance) - if discount: # noqa: RET503 + if discount: return discount.discount_code class Meta: diff --git a/main/telemetry.py b/main/telemetry.py index 669a014283..89b2af41ce 100644 --- a/main/telemetry.py +++ b/main/telemetry.py @@ -3,7 +3,6 @@ from __future__ import annotations import logging -from typing import Optional from django.conf import settings from opentelemetry import trace @@ -23,7 +22,7 @@ log = logging.getLogger(__name__) -def configure_opentelemetry() -> Optional[TracerProvider]: +def configure_opentelemetry() -> TracerProvider | None: """ Configure OpenTelemetry with appropriate instrumentations and exporters. Returns the tracer provider if configured, None otherwise. diff --git a/main/utils.py b/main/utils.py index 19e04769ad..8926ff468c 100644 --- a/main/utils.py +++ b/main/utils.py @@ -4,7 +4,7 @@ import json from datetime import date, datetime -from typing import TYPE_CHECKING, Optional, Set, Tuple, TypeVar, Union # noqa: UP035 +from typing import TYPE_CHECKING, Set, Tuple, TypeVar, Union # noqa: UP035 from urllib.parse import quote_plus import dateutil @@ -200,7 +200,7 @@ def now_datetime_with_tz(): return datetime.now(tz=pytz.timezone(settings.TIME_ZONE)) -def date_to_datetime(date: date, tzinfo: Optional[str] = None) -> datetime: +def date_to_datetime(date: date, tzinfo: str | None = None) -> datetime: """Convert a regular date to a datetime with optiona timezone info.""" ret_date = datetime.fromisocalendar(*date.isocalendar())