Skip to content

Commit 71b7239

Browse files
committed
Fix compatibility with Python 3.8+
1 parent 7c050f1 commit 71b7239

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

pendulum/datetime.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from .tz import UTC
4040
from .tz.timezone import FixedTimezone
4141
from .tz.timezone import Timezone
42+
from .utils._compat import PY38
4243

4344

4445
class DateTime(datetime.datetime, Date):
@@ -1147,6 +1148,16 @@ def __add__(self, other: datetime.timedelta) -> "DateTime":
11471148
if not isinstance(other, datetime.timedelta):
11481149
return NotImplemented
11491150

1151+
if PY38:
1152+
# This is a workaround for Python 3.8+
1153+
# since calling astimezone() will call this method
1154+
# instead of the base datetime class one.
1155+
import inspect
1156+
1157+
caller = inspect.stack()[1][3]
1158+
if caller == "astimezone":
1159+
return super().__add__(other)
1160+
11501161
return self._add_timedelta_(other)
11511162

11521163
def __radd__(self, other: datetime.timedelta) -> "DateTime":

pendulum/utils/_compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
PYPY = hasattr(sys, "pypy_version_info")
5+
PY38 = sys.version_info[:2] >= (3, 8)
56

67

78
try:

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
isolated_build = true
3-
envlist = py36, py37, py38, pypy3
3+
envlist = py36, py37, py38, py39, pypy3
44

55
[testenv]
66
whitelist_externals = poetry

0 commit comments

Comments
 (0)