From 980e5aa634b3192a1df9ccaee895a79544bdf16d Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Sun, 22 Sep 2019 16:35:00 +0100 Subject: [PATCH] Fix incorrect import in Python 3.7+ It turns out that the import of `contextlib.nullcontext` in Python 3.7+ was accidentally trying to import `contextmanager.nullcontext`, but this was never noticed because it simply fell back to the backport included here. I do not know of a great way to test this that doesn't rely on implementation details, but I have manually tested it by setting a breakpoint after the import in the `try` statement and importing `dateutil.tz` manually on Python 3.7, so this version should work. --- changelog.d/963.bugfix.rst | 2 ++ dateutil/tz/tz.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelog.d/963.bugfix.rst diff --git a/changelog.d/963.bugfix.rst b/changelog.d/963.bugfix.rst new file mode 100644 index 000000000..2b1aabc0c --- /dev/null +++ b/changelog.d/963.bugfix.rst @@ -0,0 +1,2 @@ +Fixed issue where ``dateutil.tz`` was using a backport of ``contextlib.nullcontext`` +even in Python 3.7 due to a malformed import statement. diff --git a/dateutil/tz/tz.py b/dateutil/tz/tz.py index 9d64c37a9..2460b5ed5 100644 --- a/dateutil/tz/tz.py +++ b/dateutil/tz/tz.py @@ -1823,7 +1823,7 @@ def _get_supported_offset(second_offset): try: # Python 3.7 feature - from contextmanager import nullcontext as _nullcontext + from contextlib import nullcontext as _nullcontext except ImportError: class _nullcontext(object): """