Skip to content

Commit

Permalink
Updates from pyupgrade linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Feb 9, 2024
1 parent c0ce447 commit 3756ba1
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
3 changes: 1 addition & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from logging import StreamHandler
from random import choice
from typing import Dict, List
from unittest import mock

import pytest
Expand Down Expand Up @@ -103,7 +102,7 @@ def create_library_card(self, user, library, **kwargs):
card.save()
return card

def inline_post_data(self, name, data: List[Dict]):
def inline_post_data(self, name, data: list[dict]):
"""Generic inline form data creation"""
inline = {
f"{name}-TOTAL_FORMS": len(data),
Expand Down
3 changes: 1 addition & 2 deletions virtual_library_card/geoloc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import urllib
from typing import List

from django.conf import settings

Expand Down Expand Up @@ -74,7 +73,7 @@ def mapquest_reverse_geocode(cls, data: dict) -> None:
return

# List[dict, dict]: [What should we match against, What should we change]
changes: List[List[dict, dict]] = [
changes: list[list[dict, dict]] = [
[dict(adminArea1="AS"), dict(adminArea1="US", adminArea3="AS")],
[dict(adminArea1="GU"), dict(adminArea1="US", adminArea3="GU")],
[dict(adminArea1="PR"), dict(adminArea1="US", adminArea3="PR")],
Expand Down
9 changes: 4 additions & 5 deletions virtual_library_card/profanity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
from typing import List, Optional

from better_profanity import profanity
from better_profanity.varying_string import VaryingString
Expand All @@ -13,7 +12,7 @@ class ProfanityWordList:
since it matches our need for basic censorship with common replacements but not the need to do partial string matches
"""

_ALL_CENSORED_WORDS: List[str] = []
_ALL_CENSORED_WORDS: list[str] = []

@classmethod
def contains_profanity(cls, word: str) -> bool:
Expand All @@ -25,13 +24,13 @@ def contains_profanity(cls, word: str) -> bool:
return False

@classmethod
def wordlist(cls) -> List[str]:
def wordlist(cls) -> list[str]:
if not cls._ALL_CENSORED_WORDS:
cls._generate_wordlist()
return cls._ALL_CENSORED_WORDS

@classmethod
def _generate_wordlist(cls, custom_words: Optional[List[str]] = None):
def _generate_wordlist(cls, custom_words: list[str] | None = None):
# setup and cache the profanity list
profanity.load_censor_words(custom_words=custom_words)
cls._ALL_CENSORED_WORDS = []
Expand All @@ -43,7 +42,7 @@ def _generate_wordlist(cls, custom_words: Optional[List[str]] = None):
)

@classmethod
def _generate_word_variations(cls, vstr: VaryingString) -> List[str]:
def _generate_word_variations(cls, vstr: VaryingString) -> list[str]:
"""Generate all possible variations for a given word"""
variations = []
combos = []
Expand Down
3 changes: 2 additions & 1 deletion virtuallibrarycard/business_rules/library_card.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

import csv
from collections.abc import Generator
from dataclasses import dataclass
from datetime import datetime
from io import BytesIO, StringIO
from os import linesep
from random import random
from threading import Thread
from typing import IO, Any, Generator
from typing import IO, Any

import chardet
from django.core.files.storage import FileSystemStorage
Expand Down
6 changes: 3 additions & 3 deletions virtuallibrarycard/forms/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from gettext import gettext as _
from typing import Any, Dict, Optional
from typing import Any

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
Expand Down Expand Up @@ -29,7 +29,7 @@ class Meta:
exclude = []
labels = {"user": _("User Email")}

def __init__(self, data: Dict = None, *args, **kwargs) -> None:
def __init__(self, data: dict = None, *args, **kwargs) -> None:
super().__init__(data, *args, **kwargs)

# If we have the field and also have a new instance (on create)
Expand All @@ -41,7 +41,7 @@ def __init__(self, data: Dict = None, *args, **kwargs) -> None:
<br>In case a number is provided it will be prefixed by the Library prefix"
)

def clean(self) -> Optional[Dict[str, Any]]:
def clean(self) -> dict[str, Any] | None:
super().clean()
number = self.cleaned_data.get("number")
if not self.instance.pk and number:
Expand Down
6 changes: 3 additions & 3 deletions virtuallibrarycard/views/admin_email_customize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from gettext import gettext as _
from typing import Any, Dict
from typing import Any

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
Expand Down Expand Up @@ -41,7 +41,7 @@ def _get_url_library(self):
library_id = self.kwargs["id"]
return Library.objects.get(id=library_id)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
"""The context data needs the email template rendered string
so the javascript may show a preview to the user"""
ctx = super().get_context_data(**kwargs)
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:

return ctx

def get_initial(self) -> Dict[str, Any]:
def get_initial(self) -> dict[str, Any]:
"""The intitial form data should be prefilled with the saved text"""
library = self._get_url_library()
return {
Expand Down
6 changes: 3 additions & 3 deletions virtuallibrarycard/views/views_verification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any
from urllib.request import Request

from crispy_forms.helper import FormHelper
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):
self.user = None
super().__init__(*args, **kwargs)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
if self.user:
context["user"] = self.user
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, **kwargs: Any) -> None:
self.email_missing = False
super().__init__(**kwargs)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
success = self.request.GET.get("success", None)

Expand Down
4 changes: 2 additions & 2 deletions virtuallibrarycard/widgets/buttons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any

from django import forms

Expand All @@ -10,7 +10,7 @@ class FormButtonInput(forms.widgets.Input):
template_name: str = "form_button_input.html"
href: str = None

def get_context(self, name: str, value, attrs) -> Dict[str, Any]:
def get_context(self, name: str, value, attrs) -> dict[str, Any]:
ctx = super().get_context(name, value, attrs)
ctx["widget"]["href"] = self.href
return ctx
Expand Down

0 comments on commit 3756ba1

Please sign in to comment.