diff --git a/dirty_equals/_datetime.py b/dirty_equals/_datetime.py index e52ef04..fb30aae 100644 --- a/dirty_equals/_datetime.py +++ b/dirty_equals/_datetime.py @@ -127,14 +127,6 @@ def approx_equals(self, other: datetime, delta: timedelta) -> bool: return True -def _zoneinfo(tz: str) -> ZoneInfo: - """ - Instantiate a `ZoneInfo` object from a string, falling back to `pytz.timezone` when `ZoneInfo` is not available - (most likely on Python 3.8 and webassembly). - """ - return ZoneInfo(tz) - - class IsNow(IsDatetime): """ Check if a datetime is close to now, this is similar to `IsDatetime(approx=datetime.now())`, @@ -180,7 +172,7 @@ def __init__( ``` """ if isinstance(tz, str): - tz = _zoneinfo(tz) + tz = ZoneInfo(tz) self.tz = tz diff --git a/tests/test_datetime.py b/tests/test_datetime.py index 1ba16f3..7676033 100644 --- a/tests/test_datetime.py +++ b/tests/test_datetime.py @@ -1,3 +1,4 @@ +import sys from datetime import date, datetime, timedelta, timezone from unittest.mock import Mock @@ -5,10 +6,12 @@ from dirty_equals import IsDate, IsDatetime, IsNow, IsToday -try: +if sys.version_info >= (3, 9): from zoneinfo import ZoneInfo -except ImportError: - from backports.zoneinfo import ZoneInfo +else: + # This code block is due to a typing issue with backports.zoneinfo package: + # https://github.com/pganssle/zoneinfo/issues/125 + from backports.zoneinfo._zoneinfo import ZoneInfo @pytest.mark.parametrize(