Compare commits

...

3 commits

Author SHA1 Message Date
Bart Schuurmans 7a13a2278b
Merge acae063652 into c4b21ee258 2024-04-26 11:59:23 +00:00
Bart Schuurmans acae063652 Fix new warnings from pylint upgrade 2024-04-26 13:59:16 +02:00
Bart Schuurmans c32f9faaa0 Upgrade pylint to 2.17.7 2024-04-26 13:41:01 +02:00
7 changed files with 22 additions and 27 deletions

View file

@ -400,11 +400,11 @@ def get_representative():
to sign outgoing HTTP GET requests""" to sign outgoing HTTP GET requests"""
return models.User.objects.get_or_create( return models.User.objects.get_or_create(
username=f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}", username=f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}",
defaults=dict( defaults={
email="bookwyrm@localhost", "email": "bookwyrm@localhost",
local=True, "local": True,
localname=INSTANCE_ACTOR_USERNAME, "localname": INSTANCE_ACTOR_USERNAME,
), },
)[0] )[0]

View file

@ -14,15 +14,10 @@ class CalibreImporter(Importer):
def __init__(self, *args: Any, **kwargs: Any): def __init__(self, *args: Any, **kwargs: Any):
# Add timestamp to row_mappings_guesses for date_added to avoid # Add timestamp to row_mappings_guesses for date_added to avoid
# integrity error # integrity error
row_mappings_guesses = [] self.row_mappings_guesses = [
(field, mapping + (["timestamp"] if field == "date_added" else []))
for field, mapping in self.row_mappings_guesses: for field, mapping in self.row_mappings_guesses
if field in ("date_added",): ]
row_mappings_guesses.append((field, mapping + ["timestamp"]))
else:
row_mappings_guesses.append((field, mapping))
self.row_mappings_guesses = row_mappings_guesses
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def get_shelf(self, normalized_row: dict[str, Optional[str]]) -> Optional[str]: def get_shelf(self, normalized_row: dict[str, Optional[str]]) -> Optional[str]:

View file

@ -169,7 +169,7 @@ class ActivitypubMixin:
# filter users first by whether they're using the desired software # filter users first by whether they're using the desired software
# this lets us send book updates only to other bw servers # this lets us send book updates only to other bw servers
if software: if software:
queryset = queryset.filter(bookwyrm_user=(software == "bookwyrm")) queryset = queryset.filter(bookwyrm_user=software == "bookwyrm")
# if there's a user, we only want to send to the user's followers # if there's a user, we only want to send to the user's followers
if user: if user:
queryset = queryset.filter(following=user) queryset = queryset.filter(following=user)

View file

@ -137,14 +137,14 @@ def get_file_size(nbytes):
raw_size = float(nbytes) raw_size = float(nbytes)
except (ValueError, TypeError): except (ValueError, TypeError):
return repr(nbytes) return repr(nbytes)
else:
if raw_size < 1024: if raw_size < 1024:
return f"{raw_size} bytes" return f"{raw_size} bytes"
if raw_size < 1024**2: if raw_size < 1024**2:
return f"{raw_size/1024:.2f} KB" return f"{raw_size/1024:.2f} KB"
if raw_size < 1024**3: if raw_size < 1024**3:
return f"{raw_size/1024**2:.2f} MB" return f"{raw_size/1024**2:.2f} MB"
return f"{raw_size/1024**3:.2f} GB" return f"{raw_size/1024**3:.2f} GB"
@register.filter(name="get_user_permission") @register.filter(name="get_user_permission")

View file

@ -35,7 +35,7 @@ def validate_html(html):
e for e in errors.split("\n") if not any(exclude in e for exclude in excluded) e for e in errors.split("\n") if not any(exclude in e for exclude in excluded)
) )
if errors: if errors:
raise Exception(errors) raise ValueError(errors)
validator = HtmlValidator() validator = HtmlValidator()
# will raise exceptions # will raise exceptions
@ -62,6 +62,6 @@ class HtmlValidator(HTMLParser): # pylint: disable=abstract-method
and "noreferrer" in value and "noreferrer" in value
): ):
return return
raise Exception( raise ValueError(
'Links to a new tab must have rel="nofollow noopener noreferrer"' 'Links to a new tab must have rel="nofollow noopener noreferrer"'
) )

View file

@ -225,4 +225,4 @@ def get_goal_status(user, year):
if goal.privacy != "public": if goal.privacy != "public":
return None return None
return dict(**goal.progress, **{"goal": goal.goal}) return {**goal.progress, **{"goal": goal.goal}}

View file

@ -48,7 +48,7 @@ black==22.*
celery-types==0.22.0 celery-types==0.22.0
django-stubs[compatible-mypy]==4.2.7 django-stubs[compatible-mypy]==4.2.7
mypy==1.7.1 mypy==1.7.1
pylint==2.15.0 pylint==2.17.7
pytest==8.1.1 pytest==8.1.1
pytest-cov==5.0.0 pytest-cov==5.0.0
pytest-django==4.8.0 pytest-django==4.8.0