From ff1f239a574a437ff14204ddf607d8ed22678d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 19 Nov 2023 14:41:37 -0300 Subject: [PATCH] Use typing_extensions.Self instead of TypeVar --- bookwyrm/utils/partial_date.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bookwyrm/utils/partial_date.py b/bookwyrm/utils/partial_date.py index 2bc97748c..40b89c838 100644 --- a/bookwyrm/utils/partial_date.py +++ b/bookwyrm/utils/partial_date.py @@ -4,7 +4,8 @@ from __future__ import annotations from datetime import datetime, timedelta import re -from typing import Any, Optional, Type, TypeVar, cast +from typing import Any, Optional, Type, cast +from typing_extensions import Self from django.core.exceptions import ValidationError from django.db import models @@ -23,8 +24,6 @@ __all__ = [ _partial_re = re.compile(r"(\d{4})(?:-(\d\d?))?(?:-(\d\d?))?$") _westmost_tz = timezone.get_fixed_timezone(timedelta(hours=-12)) -Partial = TypeVar("Partial", bound="PartialDate") # TODO: use Self in Python >= 3.11 - # TODO: migrate PartialDate: `datetime` => `date` # TODO: migrate PartialDateModel: `DateTimeField` => `DateField` @@ -47,7 +46,7 @@ class PartialDate(datetime): return self.strftime("%Y-%m-%d") @classmethod - def from_datetime(cls: Type[Partial], dt: datetime) -> Partial: + def from_datetime(cls, dt: datetime) -> Self: """construct a PartialDate object from a timezone-aware datetime Use subclasses to specify precision. If `dt` is naive, `ValueError` @@ -59,7 +58,7 @@ class PartialDate(datetime): return cls.combine(dt.date(), dt.time(), tzinfo=dt.tzinfo) @classmethod - def from_date_parts(cls: Type[Partial], year: int, month: int, day: int) -> Partial: + def from_date_parts(cls, year: int, month: int, day: int) -> Self: """construct a PartialDate from year, month, day. Use sublcasses to specify precision."""