diff --git a/tests/base.py b/tests/base.py index 98e1c8f..6d61740 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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 @@ -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), diff --git a/virtual_library_card/geoloc.py b/virtual_library_card/geoloc.py index 00d152d..eadbedd 100644 --- a/virtual_library_card/geoloc.py +++ b/virtual_library_card/geoloc.py @@ -1,6 +1,5 @@ import json import urllib -from typing import List from django.conf import settings @@ -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")], diff --git a/virtual_library_card/profanity.py b/virtual_library_card/profanity.py index d88a50c..fa69e34 100644 --- a/virtual_library_card/profanity.py +++ b/virtual_library_card/profanity.py @@ -1,5 +1,4 @@ import itertools -from typing import List, Optional from better_profanity import profanity from better_profanity.varying_string import VaryingString @@ -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: @@ -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 = [] @@ -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 = [] diff --git a/virtuallibrarycard/business_rules/library_card.py b/virtuallibrarycard/business_rules/library_card.py index 006a378..b541015 100644 --- a/virtuallibrarycard/business_rules/library_card.py +++ b/virtuallibrarycard/business_rules/library_card.py @@ -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 diff --git a/virtuallibrarycard/forms/forms.py b/virtuallibrarycard/forms/forms.py index a0c08c9..60ee466 100644 --- a/virtuallibrarycard/forms/forms.py +++ b/virtuallibrarycard/forms/forms.py @@ -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 @@ -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) @@ -41,7 +41,7 @@ def __init__(self, data: Dict = None, *args, **kwargs) -> None:
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: diff --git a/virtuallibrarycard/views/admin_email_customize.py b/virtuallibrarycard/views/admin_email_customize.py index 89a4bc2..1c5ce92 100644 --- a/virtuallibrarycard/views/admin_email_customize.py +++ b/virtuallibrarycard/views/admin_email_customize.py @@ -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 @@ -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) @@ -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 { diff --git a/virtuallibrarycard/views/views_verification.py b/virtuallibrarycard/views/views_verification.py index 78ffb0e..2c676b0 100644 --- a/virtuallibrarycard/views/views_verification.py +++ b/virtuallibrarycard/views/views_verification.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any from urllib.request import Request from crispy_forms.helper import FormHelper @@ -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 @@ -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) diff --git a/virtuallibrarycard/widgets/buttons.py b/virtuallibrarycard/widgets/buttons.py index eafd453..f5e0e73 100644 --- a/virtuallibrarycard/widgets/buttons.py +++ b/virtuallibrarycard/widgets/buttons.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any from django import forms @@ -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