diff --git a/poetry.lock b/poetry.lock index c300ae6b5..dba07d620 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "alabaster" @@ -1184,11 +1184,11 @@ google-auth = ">=2.14.1,<3.0.dev0" googleapis-common-protos = ">=1.56.2,<2.0.dev0" grpcio = [ {version = ">=1.33.2,<2.0dev", optional = true, markers = "extra == \"grpc\""}, - {version = ">=1.49.1,<2.0dev", optional = true, markers = "python_version >= \"3.11\" and extra == \"grpc\""}, + {version = ">=1.49.1,<2.0dev", optional = true, markers = "python_version >= \"3.11\""}, ] grpcio-status = [ {version = ">=1.33.2,<2.0.dev0", optional = true, markers = "extra == \"grpc\""}, - {version = ">=1.49.1,<2.0.dev0", optional = true, markers = "python_version >= \"3.11\" and extra == \"grpc\""}, + {version = ">=1.49.1,<2.0.dev0", optional = true, markers = "python_version >= \"3.11\""}, ] protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<5.0.0.dev0" requests = ">=2.18.0,<3.0.0.dev0" @@ -2486,29 +2486,29 @@ pyasn1 = ">=0.1.3" [[package]] name = "ruff" -version = "0.0.272" +version = "0.0.291" description = "An extremely fast Python linter, written in Rust." category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.0.272-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:ae9b57546e118660175d45d264b87e9b4c19405c75b587b6e4d21e6a17bf4fdf"}, - {file = "ruff-0.0.272-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:1609b864a8d7ee75a8c07578bdea0a7db75a144404e75ef3162e0042bfdc100d"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ee76b4f05fcfff37bd6ac209d1370520d509ea70b5a637bdf0a04d0c99e13dff"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:48eccf225615e106341a641f826b15224b8a4240b84269ead62f0afd6d7e2d95"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:677284430ac539bb23421a2b431b4ebc588097ef3ef918d0e0a8d8ed31fea216"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:9c4bfb75456a8e1efe14c52fcefb89cfb8f2a0d31ed8d804b82c6cf2dc29c42c"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:86bc788245361a8148ff98667da938a01e1606b28a45e50ac977b09d3ad2c538"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:27b2ea68d2aa69fff1b20b67636b1e3e22a6a39e476c880da1282c3e4bf6ee5a"}, - {file = "ruff-0.0.272-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bd2bbe337a3f84958f796c77820d55ac2db1e6753f39d1d1baed44e07f13f96d"}, - {file = "ruff-0.0.272-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:d5a208f8ef0e51d4746930589f54f9f92f84bb69a7d15b1de34ce80a7681bc00"}, - {file = "ruff-0.0.272-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:905ff8f3d6206ad56fcd70674453527b9011c8b0dc73ead27618426feff6908e"}, - {file = "ruff-0.0.272-py3-none-musllinux_1_2_i686.whl", hash = "sha256:19643d448f76b1eb8a764719072e9c885968971bfba872e14e7257e08bc2f2b7"}, - {file = "ruff-0.0.272-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:691d72a00a99707a4e0b2846690961157aef7b17b6b884f6b4420a9f25cd39b5"}, - {file = "ruff-0.0.272-py3-none-win32.whl", hash = "sha256:dc406e5d756d932da95f3af082814d2467943631a587339ee65e5a4f4fbe83eb"}, - {file = "ruff-0.0.272-py3-none-win_amd64.whl", hash = "sha256:a37ec80e238ead2969b746d7d1b6b0d31aa799498e9ba4281ab505b93e1f4b28"}, - {file = "ruff-0.0.272-py3-none-win_arm64.whl", hash = "sha256:06b8ee4eb8711ab119db51028dd9f5384b44728c23586424fd6e241a5b9c4a3b"}, - {file = "ruff-0.0.272.tar.gz", hash = "sha256:273a01dc8c3c4fd4c2af7ea7a67c8d39bb09bce466e640dd170034da75d14cab"}, + {file = "ruff-0.0.291-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:b97d0d7c136a85badbc7fd8397fdbb336e9409b01c07027622f28dcd7db366f2"}, + {file = "ruff-0.0.291-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:6ab44ea607967171e18aa5c80335237be12f3a1523375fa0cede83c5cf77feb4"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a04b384f2d36f00d5fb55313d52a7d66236531195ef08157a09c4728090f2ef0"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b727c219b43f903875b7503a76c86237a00d1a39579bb3e21ce027eec9534051"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:87671e33175ae949702774071b35ed4937da06f11851af75cd087e1b5a488ac4"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:b75f5801547f79b7541d72a211949754c21dc0705c70eddf7f21c88a64de8b97"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b09b94efdcd162fe32b472b2dd5bf1c969fcc15b8ff52f478b048f41d4590e09"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d5b56bc3a2f83a7a1d7f4447c54d8d3db52021f726fdd55d549ca87bca5d747"}, + {file = "ruff-0.0.291-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13f0d88e5f367b2dc8c7d90a8afdcfff9dd7d174e324fd3ed8e0b5cb5dc9b7f6"}, + {file = "ruff-0.0.291-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b3eeee1b1a45a247758ecdc3ab26c307336d157aafc61edb98b825cadb153df3"}, + {file = "ruff-0.0.291-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:6c06006350c3bb689765d71f810128c9cdf4a1121fd01afc655c87bab4fb4f83"}, + {file = "ruff-0.0.291-py3-none-musllinux_1_2_i686.whl", hash = "sha256:fd17220611047de247b635596e3174f3d7f2becf63bd56301fc758778df9b629"}, + {file = "ruff-0.0.291-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5383ba67ad360caf6060d09012f1fb2ab8bd605ab766d10ca4427a28ab106e0b"}, + {file = "ruff-0.0.291-py3-none-win32.whl", hash = "sha256:1d5f0616ae4cdc7a938b493b6a1a71c8a47d0300c0d65f6e41c281c2f7490ad3"}, + {file = "ruff-0.0.291-py3-none-win_amd64.whl", hash = "sha256:8a69bfbde72db8ca1c43ee3570f59daad155196c3fbe357047cd9b77de65f15b"}, + {file = "ruff-0.0.291-py3-none-win_arm64.whl", hash = "sha256:d867384a4615b7f30b223a849b52104214442b5ba79b473d7edd18da3cde22d6"}, + {file = "ruff-0.0.291.tar.gz", hash = "sha256:c61109661dde9db73469d14a82b42a88c7164f731e6a3b0042e71394c1c7ceed"}, ] [[package]] @@ -3009,4 +3009,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "0661637728906e674d7def472d233da4cb44c22a8b250876c55f2f28386dd430" +content-hash = "f0ab9efef84d60d22aa42b07f5ccf02e5895b6801d62c07567150b3a82f59a3d" diff --git a/pyproject.toml b/pyproject.toml index 67af80f23..2848ec1dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ Faker = "18.13.0" coverage = {extras = ["toml"], version = "^7.0.0"} isort = "5.12.0" black = "23.9.1" -ruff = "0.0.272" +ruff = "0.0.291" pre-commit = "3.4.0" pyparsing = "^3.0.9" pydot = "^1.4.2" @@ -181,6 +181,7 @@ ignore = [ "N818", # exception class should have Error suffix "PLW2901", # loop variable overwritten "RUF005", # use spread operator instead of concatenation + "RUF012", ] [tool.ruff.per-file-ignores] diff --git a/website/facedetection/models.py b/website/facedetection/models.py index c13667e21..ed175f4e0 100644 --- a/website/facedetection/models.py +++ b/website/facedetection/models.py @@ -281,13 +281,13 @@ def encoding(self) -> list[float]: if hasattr(self, "_encoding"): return self._encoding - self._encoding = [getattr(self, f"_field{i}") for i in range(0, 128)] + self._encoding = [getattr(self, f"_field{i}") for i in range(128)] return self._encoding @encoding.setter def encoding(self, value): self._encoding = value - for i in range(0, 128): + for i in range(128): setattr(self, f"_field{i}", value[i]) def encoding_match_function(self) -> str: @@ -297,7 +297,7 @@ def encoding_match_function(self) -> str: and checks whether it's less than a threshold of 0.49. """ sum_of_squares = " + ".join( - f"power(_field{i} - {self.encoding[i]}, 2)" for i in range(0, 128) + f"power(_field{i} - {self.encoding[i]}, 2)" for i in range(128) ) euclidean_distance = f"sqrt({sum_of_squares})" diff --git a/website/mailinglists/gsuite.py b/website/mailinglists/gsuite.py index a4bfddab7..170c3e8d6 100644 --- a/website/mailinglists/gsuite.py +++ b/website/mailinglists/gsuite.py @@ -2,6 +2,7 @@ import logging from random import random from time import sleep +from typing import Optional from django.conf import settings from django.utils.datastructures import ImmutableList @@ -372,7 +373,7 @@ def _get_default_lists(self): self._automatic_to_group(ml) for ml in get_automatic_lists() ] - def sync_mailing_lists(self, lists: list[GroupData] = None): + def sync_mailing_lists(self, lists: Optional[list[GroupData]] = None): """Sync mailing lists with GSuite. Lists are only deleted if all lists are synced and thus no lists are passed to this function. :param lists: optional parameter to determine which lists to sync diff --git a/website/moneybirdsynchronization/administration.py b/website/moneybirdsynchronization/administration.py index 5c36049d0..541a4db27 100644 --- a/website/moneybirdsynchronization/administration.py +++ b/website/moneybirdsynchronization/administration.py @@ -8,7 +8,7 @@ import logging from abc import ABC, abstractmethod from functools import reduce -from typing import Union +from typing import Optional, Union from urllib.parse import urljoin from django.utils import timezone @@ -27,7 +27,7 @@ def __init__(self, administration_id: int): self.administration_id = administration_id @abstractmethod - def get(self, resource_path: str, params: dict = None): + def get(self, resource_path: str, params: Optional[dict] = None): """Do a GET on the Moneybird administration.""" @abstractmethod @@ -48,7 +48,7 @@ class InvalidResourcePath(Exception): class Error(Exception): """An exception that can be thrown while using the administration.""" - def __init__(self, status_code: int, description: str = None): + def __init__(self, status_code: int, description: Optional[str] = None): """Create a new administration error.""" msg = f"API error {status_code}" if description: @@ -155,7 +155,7 @@ def _create_session(self) -> requests.Session: session.headers.update({"Authorization": f"Bearer {self.key}"}) return session - def get(self, resource_path: str, params: dict = None): + def get(self, resource_path: str, params: Optional[dict] = None): """Do a GET on the Moneybird administration.""" url = self._build_url(resource_path) logging.debug(f"GET {url} {params}") @@ -178,7 +178,7 @@ def patch(self, resource_path: str, data: dict): response = self.session.patch(url, data=data) return self._process_response(response) - def delete(self, resource_path: str, data: dict = None): + def delete(self, resource_path: str, data: Optional[dict] = None): """Do a DELETE on the Moneybird administration.""" url = self._build_url(resource_path) logging.debug(f"DELETE {url}") diff --git a/website/payments/admin.py b/website/payments/admin.py index c9b1182e6..eb056ae96 100644 --- a/website/payments/admin.py +++ b/website/payments/admin.py @@ -1,6 +1,7 @@ """Registers admin interfaces for the payments module.""" import csv from collections import OrderedDict +from typing import Optional from django.contrib import admin, messages from django.contrib.admin import ModelAdmin @@ -434,9 +435,9 @@ def save_formset(self, request, form, formset, change): def changeform_view( self, request: HttpRequest, - object_id: str = None, + object_id: Optional[str] = None, form_url: str = "", - extra_context: dict = None, + extra_context: Optional[dict] = None, ) -> HttpResponse: """Render the change formview. diff --git a/website/payments/services.py b/website/payments/services.py index 7e5a1e11d..9a34ee0fb 100644 --- a/website/payments/services.py +++ b/website/payments/services.py @@ -1,6 +1,6 @@ """The services defined by the payments package.""" import datetime -from typing import Union +from typing import Optional, Union from django.conf import settings from django.core import mail @@ -135,7 +135,7 @@ def delete_payment(model: Model, member: Member = None, ignore_change_window=Fal payable.model.save() -def update_last_used(queryset: QuerySet, date: datetime.date = None) -> int: +def update_last_used(queryset: QuerySet, date: Optional[datetime.date] = None) -> int: """Update the last used field of a BankAccount queryset. :param queryset: Queryset of BankAccounts diff --git a/website/registrations/tests/test_models.py b/website/registrations/tests/test_models.py index 2ac7dbce3..18a956767 100644 --- a/website/registrations/tests/test_models.py +++ b/website/registrations/tests/test_models.py @@ -59,11 +59,7 @@ def test_str(self): entry = Entry(renewal=self.renewal) self.assertEqual( str(entry), - "{} {} ({})".format( - self.member.first_name, - self.member.last_name, - self.member.email, - ), + f"{self.member.first_name} {self.member.last_name} ({self.member.email})", ) @freeze_time("2019-01-01") @@ -322,11 +318,7 @@ def setUp(self): def test_str(self): self.assertEqual( str(self.renewal), - "{} {} ({})".format( - self.member.first_name, - self.member.last_name, - self.member.email, - ), + f"{self.member.first_name} {self.member.last_name} ({self.member.email})", ) def test_save(self): diff --git a/website/utils/media/services.py b/website/utils/media/services.py index 04bc7491e..1cde371a2 100644 --- a/website/utils/media/services.py +++ b/website/utils/media/services.py @@ -1,4 +1,5 @@ import io +from typing import Optional from django.conf import settings from django.core.files.base import ContentFile @@ -32,7 +33,7 @@ def get_media_url( file, attachment=False, absolute_url: bool = False, - expire_seconds: int = None, + expire_seconds: Optional[int] = None, ): """Get the url of the provided media file to serve in a browser. @@ -63,7 +64,7 @@ def get_thumbnail_url( file, size: str, absolute_url: bool = False, - expire_seconds: int = None, + expire_seconds: Optional[int] = None, ): name = file if isinstance(file, (ImageFieldFile, FieldFile)):