Skip to content

Commit c7dcf6e

Browse files
jensensclaude
andcommitted
fix: use timezone.utc instead of datetime.UTC for Python 3.10 compat
datetime.UTC was added in Python 3.11, but the package declares requires-python = ">=3.10" and ships the 3.10 classifier. Two test files imported datetime.UTC, breaking test collection on 3.10: ImportError: cannot import name 'UTC' from 'datetime' Replace with timezone.utc (available since 3.2). Fixes #10. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 05dde07 commit c7dcf6e

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## unreleased
4+
5+
- Fix Python 3.10 incompatibility in the test suite: replace the
6+
Python 3.11+ `datetime.UTC` import with `timezone.utc` in
7+
`tests/test_pg_json.py` and `tests/test_known_types.py` [#10]
8+
39
## 1.6.1 (2026-02-27)
410

511
- CRITICAL Linux!

tests/test_known_types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from datetime import time
1010
from datetime import timedelta
1111
from datetime import timezone
12-
from datetime import UTC
1312
from decimal import Decimal
1413

1514
import json
@@ -58,13 +57,13 @@ def test_year_boundaries(self, year):
5857
assert restored == dt
5958

6059
def test_tz_stdlib_utc(self):
61-
dt = datetime(2025, 1, 1, tzinfo=UTC)
60+
dt = datetime(2025, 1, 1, tzinfo=timezone.utc)
6261
data = pickle.dumps(dt, protocol=3)
6362
result = json.loads(zodb_json_codec.pickle_to_json(data))
6463
assert result == {"@dt": "2025-01-01T00:00:00+00:00"}
6564

6665
def test_roundtrip_tz_stdlib_utc(self):
67-
dt = datetime(2025, 1, 1, tzinfo=UTC)
66+
dt = datetime(2025, 1, 1, tzinfo=timezone.utc)
6867
data = pickle.dumps(dt, protocol=3)
6968
json_str = zodb_json_codec.pickle_to_json(data)
7069
restored = pickle.loads(zodb_json_codec.json_to_pickle(json_str))

tests/test_pg_json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from datetime import date
77
from datetime import datetime
88
from datetime import timedelta
9-
from datetime import UTC
9+
from datetime import timezone
1010
from decimal import Decimal
1111
from uuid import UUID
1212

@@ -114,7 +114,7 @@ def _assert_match(self, record):
114114
assert actual == expected
115115

116116
def test_datetime(self):
117-
dt = datetime(2024, 6, 15, 12, 30, 45, tzinfo=UTC)
117+
dt = datetime(2024, 6, 15, 12, 30, 45, tzinfo=timezone.utc)
118118
record = make_zodb_record("myapp", "Obj", {"created": dt})
119119
self._assert_match(record)
120120

@@ -143,7 +143,7 @@ def test_uuid(self):
143143
def test_mixed_types(self):
144144
state = {
145145
"title": "Test",
146-
"created": datetime(2024, 1, 1, tzinfo=UTC),
146+
"created": datetime(2024, 1, 1, tzinfo=timezone.utc),
147147
"score": Decimal("3.14"),
148148
"tags": frozenset(["a", "b"]),
149149
"coords": (1.0, 2.0),

0 commit comments

Comments
 (0)