From 6d5987b43dfad843864922a50b90f8f495750699 Mon Sep 17 00:00:00 2001 From: FasterSpeeding Date: Mon, 18 Nov 2024 01:38:09 +0000 Subject: [PATCH] A few more 3.11 changes (#970) --- tanjun/conversion.py | 4 ++-- tests/test_conversion.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tanjun/conversion.py b/tanjun/conversion.py index 778c409f7..e22477624 100644 --- a/tanjun/conversion.py +++ b/tanjun/conversion.py @@ -1406,7 +1406,7 @@ def to_datetime(value: str, /) -> datetime.datetime: except StopIteration: raise ValueError("Not a valid datetime") from None - return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc) + return datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC) _VALID_DATETIME_STYLES = frozenset(("t", "T", "d", "D", "f", "F", "R")) @@ -1453,7 +1453,7 @@ def from_datetime(value: datetime.datetime | datetime.timedelta, /, *, style: st If an invalid style is provided. """ if isinstance(value, datetime.timedelta): - return from_datetime(datetime.datetime.now(tz=datetime.timezone.utc) + value, style="R") + return from_datetime(datetime.datetime.now(tz=datetime.UTC) + value, style="R") if style not in _VALID_DATETIME_STYLES: raise ValueError(f"Invalid style: {style}") diff --git a/tests/test_conversion.py b/tests/test_conversion.py index c7dc8fce5..dcd4a2be7 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -1819,8 +1819,8 @@ def test_split_url_when_wrapped(): @pytest.mark.parametrize( ("value", "expected"), [ - ("", datetime.datetime(1973, 11, 28, 7, 52, 3, tzinfo=datetime.timezone.utc)), - ("", datetime.datetime(1970, 2, 7, 9, 48, 53, tzinfo=datetime.timezone.utc)), + ("", datetime.datetime(1973, 11, 28, 7, 52, 3, tzinfo=datetime.UTC)), + ("", datetime.datetime(1970, 2, 7, 9, 48, 53, tzinfo=datetime.UTC)), ], ) def test_to_datetime(value: str, expected: datetime.datetime): @@ -1834,7 +1834,7 @@ def test_to_datetime_with_invalid_values(value: str): def test_from_datetime(): - date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.timezone.utc) + date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.UTC) result = tanjun.conversion.from_datetime(date, style="d") @@ -1842,7 +1842,7 @@ def test_from_datetime(): def test_from_datetime_with_default_style(): - date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.timezone.utc) + date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.UTC) result = tanjun.conversion.from_datetime(date) @@ -1857,14 +1857,14 @@ def test_from_datetime_for_naive_datetime(): def test_from_datetime_for_invalid_style(): - date = datetime.datetime.now(tz=datetime.timezone.utc) + date = datetime.datetime.now(tz=datetime.UTC) with pytest.raises(ValueError, match="Invalid style: granddad"): tanjun.conversion.from_datetime(date, style="granddad") def test_from_datetime_for_time_delta(): - with freezegun.freeze_time(datetime.datetime(2022, 12, 30, 6, 33, 47, 52643, tzinfo=datetime.timezone.utc)): + with freezegun.freeze_time(datetime.datetime(2022, 12, 30, 6, 33, 47, 52643, tzinfo=datetime.UTC)): result = tanjun.conversion.from_datetime(datetime.timedelta(days=21, hours=23, minutes=32, seconds=34)) assert result == ""