Skip to content

Commit

Permalink
Implicit optional conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Feb 14, 2024
1 parent 048bc35 commit 1704695
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tests/admin/test_library_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
2 changes: 1 addition & 1 deletion tests/admin/test_library_card_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
4 changes: 3 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions virtual_library_card/api/dynamic_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion virtual_library_card/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions virtuallibrarycard/business_rules/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions virtuallibrarycard/business_rules/library_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion virtuallibrarycard/forms/forms.py
Original file line number Diff line number Diff line change
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 = None, *args, **kwargs) -> None:
super().__init__(data, *args, **kwargs)

# If we have the field and also have a new instance (on create)
Expand Down

0 comments on commit 1704695

Please sign in to comment.