diff --git a/kombu/asynchronous/timer.py b/kombu/asynchronous/timer.py index 21ad37c14..8feece314 100644 --- a/kombu/asynchronous/timer.py +++ b/kombu/asynchronous/timer.py @@ -13,23 +13,24 @@ from kombu.log import get_logger -try: - from pytz import utc -except ImportError: # pragma: no cover - utc = None + +if sys.version_info >= (3, 9): + from zoneinfo import ZoneInfo +else: + from backports.zoneinfo import ZoneInfo __all__ = ('Entry', 'Timer', 'to_timestamp') logger = get_logger(__name__) DEFAULT_MAX_INTERVAL = 2 -EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=utc) +EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=ZoneInfo("UTC")) IS_PYPY = hasattr(sys, 'pypy_version_info') scheduled = namedtuple('scheduled', ('eta', 'priority', 'entry')) -def to_timestamp(d, default_timezone=utc, time=monotonic): +def to_timestamp(d, default_timezone=ZoneInfo("UTC"), time=monotonic): """Convert datetime to timestamp. If d' is already a timestamp, then that will be used. diff --git a/requirements/test.txt b/requirements/test.txt index 9b8ca320f..d12f7c416 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,4 +1,4 @@ -pytz>dev pytest~=7.0.1 pytest-sugar Pyro4 +backports.zoneinfo>=0.2.1; python_version < '3.9' diff --git a/t/unit/utils/test_json.py b/t/unit/utils/test_json.py index 6af1c13be..1a83b5199 100644 --- a/t/unit/utils/test_json.py +++ b/t/unit/utils/test_json.py @@ -1,15 +1,19 @@ from collections import namedtuple from datetime import datetime from decimal import Decimal +import sys from unittest.mock import MagicMock, Mock from uuid import uuid4 import pytest -import pytz from kombu.utils.encoding import str_to_bytes from kombu.utils.json import _DecodeError, dumps, loads +if sys.version_info >= (3, 9): + from zoneinfo import ZoneInfo +else: + from backports.zoneinfo import ZoneInfo class Custom: @@ -24,7 +28,7 @@ class test_JSONEncoder: def test_datetime(self): now = datetime.utcnow() - now_utc = now.replace(tzinfo=pytz.utc) + now_utc = now.replace(tzinfo=ZoneInfo("UTC")) stripped = datetime(*now.timetuple()[:3]) serialized = loads(dumps({ 'datetime': now,