aboutsummaryrefslogtreecommitdiff
path: root/dateutil
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2018-08-14 10:09:08 -0400
committerPaul Ganssle <paul@ganssle.io>2018-08-14 10:58:16 -0400
commit2e6138c75d01aade30554d6095d5aa112e8aa532 (patch)
treeb5d28519fa173ed7c904fa965f83e6fc5e8e412c /dateutil
parent886ec3ee317aa1a15f1accd8bc6031e541ad36e1 (diff)
downloaddateutil-2e6138c75d01aade30554d6095d5aa112e8aa532.tar.gz
Stop trying to store None in weakref cache
None is a singleton and a weak reference to it will never expire, and in this case it is used more as a soft failure mode than as an actual value to return. By special-casing this, the invariant that: gettz(x) is gettz(x) is preserved in all cases *except* when something on the underlying system changes such that `x` does not refer to a valid time zone in the first call, but does refer to a valid time zone in the second call. This could happen if `x` is added to the zoneinfo data, or if the local time zone changes such that `x` is now a valid specifier for the local time.
Diffstat (limited to 'dateutil')
-rw-r--r--dateutil/test/test_tz.py1
-rw-r--r--dateutil/tz/tz.py7
2 files changed, 6 insertions, 2 deletions
diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py
index 3140269..a65d387 100644
--- a/dateutil/test/test_tz.py
+++ b/dateutil/test/test_tz.py
@@ -1076,7 +1076,6 @@ class GettzTest(unittest.TestCase, TzFoldMixin):
@pytest.mark.gettz
-@pytest.mark.xfail
def test_gettz_badzone():
# Make sure passing a bad TZ string to gettz returns None
# GH #800
diff --git a/dateutil/tz/tz.py b/dateutil/tz/tz.py
index ba0d8b7..3caac67 100644
--- a/dateutil/tz/tz.py
+++ b/dateutil/tz/tz.py
@@ -1539,10 +1539,15 @@ def __get_gettz():
if rv is None:
rv = self.nocache(name=name)
- if not (name is None or isinstance(rv, tzlocal_classes)):
+ if not (name is None
+ or isinstance(rv, tzlocal_classes)
+ or rv is None):
# tzlocal is slightly more complicated than the other
# time zone providers because it depends on environment
# at construction time, so don't cache that.
+ #
+ # We also cannot store weak references to None, so we
+ # will also not store that.
self.__instances[name] = rv
return rv