diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 99dd3f0f8..304a3c440 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,9 +20,6 @@ repos: rev: v3.17.0 hooks: - id: pyupgrade - # TODO: Remove when Pydantic supports `datetime.date | None` type annotation. - # Otherwise, `pyupgrade` will rewrite from `Optional[datetime.date]`. - exclude: ^src/palace/manager/api/circulation.py args: - --py310-plus diff --git a/src/palace/manager/api/circulation.py b/src/palace/manager/api/circulation.py index 6952e080e..f15eabffa 100644 --- a/src/palace/manager/api/circulation.py +++ b/src/palace/manager/api/circulation.py @@ -5,7 +5,7 @@ import logging from abc import ABC, abstractmethod from collections.abc import Iterable, Mapping -from typing import Literal, Optional, TypeVar +from typing import Literal, TypeVar import flask import requests @@ -564,9 +564,7 @@ class BaseCirculationApiSettings(BaseSettings): ) } - # TODO: Using `Optional[datetime.date]` here because Pydantic does not - # currently handle the annotation of `datetime.date | None` properly. - subscription_activation_date: Optional[datetime.date] = FormField( + subscription_activation_date: datetime.date | None = FormField( default=None, form=ConfigurationFormItem( label=_("Collection Subscription Activation Date"), @@ -579,7 +577,7 @@ class BaseCirculationApiSettings(BaseSettings): required=False, ), ) - subscription_expiration_date: Optional[datetime.date] = FormField( + subscription_expiration_date: datetime.date | None = FormField( default=None, form=ConfigurationFormItem( label=_("Collection Subscription Expiration Date"), diff --git a/tests/manager/api/admin/test_form_data.py b/tests/manager/api/admin/test_form_data.py index 1c1a02023..d4a8ad220 100644 --- a/tests/manager/api/admin/test_form_data.py +++ b/tests/manager/api/admin/test_form_data.py @@ -1,3 +1,5 @@ +import datetime + from werkzeug.datastructures import ImmutableMultiDict from palace.manager.api.admin.form_data import ProcessFormData @@ -46,6 +48,22 @@ class MockSettings(BaseSettings): description="Another date.", ), ) + field6: datetime.date | None = FormField( + None, + form=ConfigurationFormItem( + label="Another date field with a date type", + type=ConfigurationFormItemType.DATE, + description="A python date.", + ), + ) + field7: datetime.date | None = FormField( + None, + form=ConfigurationFormItem( + label="Another date field with a date type", + type=ConfigurationFormItemType.DATE, + description="A python date.", + ), + ) def test_get_settings(): @@ -59,6 +77,8 @@ def test_get_settings(): ("field3", "value5"), ("field4", "2024-10-23"), ("field5", ""), + ("field6", "2024-10-23"), + ("field7", ""), ] ) settings = ProcessFormData.get_settings(MockSettings, data) @@ -67,3 +87,5 @@ def test_get_settings(): assert settings.field3 == "value5" assert settings.field4 == "2024-10-23" assert settings.field5 is None + assert settings.field6 == datetime.date(2024, 10, 23) + assert settings.field7 is None