Skip to content

Commit

Permalink
Fix incorrect import in Python 3.7+
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pganssle committed Sep 22, 2019
1 parent 22b43cb commit 980e5aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 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.
2 changes: 1 addition & 1 deletion dateutil/tz/tz.py
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 980e5aa

Please sign in to comment.