Skip to content

Commit

Permalink
Update Ruff to 0.0.291 (#3405)
Browse files Browse the repository at this point in the history
* Update Ruff to 0.0.291

* disable RUF012
  • Loading branch information
ColonelPhantom authored Sep 29, 2023
1 parent b44f04f commit 0dab33c
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 48 deletions.
44 changes: 22 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions website/facedetection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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})"

Expand Down
3 changes: 2 additions & 1 deletion website/mailinglists/gsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions website/moneybirdsynchronization/administration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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}")
Expand All @@ -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}")
Expand Down
5 changes: 3 additions & 2 deletions website/payments/admin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions website/payments/services.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions website/registrations/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions website/utils/media/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io
from typing import Optional

from django.conf import settings
from django.core.files.base import ContentFile
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)):
Expand Down

0 comments on commit 0dab33c

Please sign in to comment.