From 170469574da0ea7ce78d70c54c922c7c7d506c9a Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 9 Feb 2024 16:15:26 -0400 Subject: [PATCH] Implicit optional conversion. --- tests/admin/test_library_admin_views.py | 2 +- tests/admin/test_library_card_admin_views.py | 2 +- tests/base.py | 4 +++- virtual_library_card/api/dynamic_links.py | 4 ++-- virtual_library_card/sender.py | 2 +- virtuallibrarycard/business_rules/library.py | 16 ++++++++-------- .../business_rules/library_card.py | 6 +++--- virtuallibrarycard/forms/forms.py | 2 +- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/admin/test_library_admin_views.py b/tests/admin/test_library_admin_views.py index 4c90987..2a7d186 100644 --- a/tests/admin/test_library_admin_views.py +++ b/tests/admin/test_library_admin_views.py @@ -41,7 +41,7 @@ def _get_library_change_data(self, library, **changes): return data def _add_library_states_data( - self, data: dict, places: list[str] = None, library=None + self, data: dict, places: list[str] | None = None, library=None ): """Helper function for change form data, for the inline library form""" places = places or [] diff --git a/tests/admin/test_library_card_admin_views.py b/tests/admin/test_library_card_admin_views.py index 9f7758a..df4d5c7 100644 --- a/tests/admin/test_library_card_admin_views.py +++ b/tests/admin/test_library_card_admin_views.py @@ -14,7 +14,7 @@ class TestLibraryCardAdminViews(BaseAdminUnitTest): MODEL = LibraryCard MODEL_ADMIN = LibraryCardAdmin - def _get_card_data(self, card: LibraryCard = None, **data): + def _get_card_data(self, card: LibraryCard | None = None, **data): initial = { "number": "", "created": "", diff --git a/tests/base.py b/tests/base.py index 6d61740..e0703c7 100644 --- a/tests/base.py +++ b/tests/base.py @@ -134,7 +134,9 @@ def tearDown(self): self._transaction.__exit__(None, None, None) super().tearDown() - def do_library_card_signup_flow(self, client: Client, library: Library = None): + def do_library_card_signup_flow( + self, client: Client, library: Library | None = None + ): """A common flow which is needed multiple times""" if not library: diff --git a/virtual_library_card/api/dynamic_links.py b/virtual_library_card/api/dynamic_links.py index f9122c4..ddc86a7 100644 --- a/virtual_library_card/api/dynamic_links.py +++ b/virtual_library_card/api/dynamic_links.py @@ -39,8 +39,8 @@ def _request( self, method: Literal["get"] | Literal["post"], path: str, - data: Any = None, - json: dict = None, + data: Any | None = None, + json: dict | None = None, ) -> Any: """Make a REST request to the dynamic links API :param method: The HTTP method diff --git a/virtual_library_card/sender.py b/virtual_library_card/sender.py index dc6e537..96b0407 100644 --- a/virtual_library_card/sender.py +++ b/virtual_library_card/sender.py @@ -26,7 +26,7 @@ def text_whitespaces_to_html(string: str) -> str: def send_user_welcome( library: Library, user: CustomUser, - card_number: str = None, + card_number: str | None = None, ): """Send out a welcome email which has two optional parts - User welcome for a new card diff --git a/virtuallibrarycard/business_rules/library.py b/virtuallibrarycard/business_rules/library.py index ee86722..b99c2af 100644 --- a/virtuallibrarycard/business_rules/library.py +++ b/virtuallibrarycard/business_rules/library.py @@ -6,10 +6,10 @@ class LibraryRules: def validate_user_address_fields( cls, library: Library, - city: str = None, - county: str = None, - state: str = None, - country: str = None, + city: str | None = None, + county: str | None = None, + state: str | None = None, + country: str | None = None, ) -> bool: """Validate whether the given address fields are valid for a user that would signup for a given library - Country, State or City, at least one must be within the list of places of the library @@ -31,10 +31,10 @@ def validate_user_address_fields( def _place_hierarchy_match( cls, place: Place, - city: str = None, - county: str = None, - state: str = None, - country: str = None, + city: str | None = None, + county: str | None = None, + state: str | None = None, + country: str | None = None, ) -> bool: """Test from the current place all the way to the last parent available. All levels of the place hierarchy MUST match even if the value isn't provided in the keyword args. diff --git a/virtuallibrarycard/business_rules/library_card.py b/virtuallibrarycard/business_rules/library_card.py index b541015..95c21c8 100644 --- a/virtuallibrarycard/business_rules/library_card.py +++ b/virtuallibrarycard/business_rules/library_card.py @@ -22,7 +22,7 @@ class LibraryCardRules: @classmethod def new_card( - cls, user: CustomUser, library: Library, number: str = None + cls, user: CustomUser, library: Library, number: str | None = None ) -> tuple[LibraryCard, bool]: """Generate a new card only of a card does not exist for this user and library Also send the welcome email""" @@ -50,7 +50,7 @@ def bulk_upload_csv( cls, library: Library, fileio: IO, - admin_user: CustomUser = None, + admin_user: CustomUser | None = None, _async: bool = False, ) -> LibraryCardBulkUpload: """Bulk upload a CSV of library users with information enough to generate cards @@ -63,7 +63,7 @@ def __init__( self, library: Library, fileio: IO, - admin_user: CustomUser = None, + admin_user: CustomUser | None = None, _async: bool = True, ) -> None: self.library = library diff --git a/virtuallibrarycard/forms/forms.py b/virtuallibrarycard/forms/forms.py index 60ee466..a2a0dd5 100644 --- a/virtuallibrarycard/forms/forms.py +++ b/virtuallibrarycard/forms/forms.py @@ -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 = None, *args, **kwargs) -> None: super().__init__(data, *args, **kwargs) # If we have the field and also have a new instance (on create)