From 5f5febfdb931aa8df9f1cd6db4a6ab6fc756d0c4 Mon Sep 17 00:00:00 2001 From: Tim DiLauro Date: Fri, 13 Dec 2024 14:08:41 -0500 Subject: [PATCH] Use `datetime`, instead of string, for subscription dates. --- .pre-commit-config.yaml | 3 +++ src/palace/manager/api/circulation.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 304a3c440..99dd3f0f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,9 @@ 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 127e25bdf..dcd029c00 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, TypeVar +from typing import Literal, Optional, TypeVar import flask import requests @@ -563,7 +563,9 @@ class BaseCirculationApiSettings(BaseSettings): ) } - subscription_activation_date: str | None = FormField( + # 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( default=None, form=ConfigurationFormItem( label=_("Collection Subscription Activation Date"), @@ -576,7 +578,7 @@ class BaseCirculationApiSettings(BaseSettings): required=False, ), ) - subscription_expiration_date: str | None = FormField( + subscription_expiration_date: Optional[datetime.date] = FormField( default=None, form=ConfigurationFormItem( label=_("Collection Subscription Expiration Date"),