diff --git a/AUTHORS.md b/AUTHORS.md index 13a32f627aa4c769f4564a4ceba0dd3c7ab8c879_QVVUSE9SUy5tZA==..18926353396b9fa1c36786e675cbd34d14bc5b1e_QVVUSE9SUy5tZA== 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -26,7 +26,6 @@ - Brook Li (gh: @absreim) **D** - Carlos <carlosxl@MASKED> - Chris van den Berg (gh: bergvca) **D** -- Christopher Cordero <ccordero@pm.me> (gh: cs-cordero) **D** - Christopher Corley <cscorley@MASKED> - Claudio Canepa <ccanepacc@MASKED> - Corey Girard <corey.r.girard@gmail.com> (gh: @coreygirard) diff --git a/changelog.d/672.bugfix.rst b/changelog.d/672.bugfix.rst deleted file mode 100644 index 13a32f627aa4c769f4564a4ceba0dd3c7ab8c879_Y2hhbmdlbG9nLmQvNjcyLmJ1Z2ZpeC5yc3Q=..0000000000000000000000000000000000000000 --- a/changelog.d/672.bugfix.rst +++ /dev/null @@ -1,1 +0,0 @@ -Switched the ``tzoffset``, ``tzstr`` and ``gettz`` caches over to using weak references, so that the cache expires when no other references to the original ``tzinfo`` objects exist. This cache-expiry behavior is not considered part of the public interface and may change in the future. Requested by @pganssle (gh issue #635), implemented by @cs-cordero (gh pr #672). diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py index 13a32f627aa4c769f4564a4ceba0dd3c7ab8c879_ZGF0ZXV0aWwvdGVzdC90ZXN0X3R6LnB5..18926353396b9fa1c36786e675cbd34d14bc5b1e_ZGF0ZXV0aWwvdGVzdC90ZXN0X3R6LnB5 100644 --- a/dateutil/test/test_tz.py +++ b/dateutil/test/test_tz.py @@ -14,8 +14,6 @@ import sys import base64 import copy -import gc -import weakref from functools import partial @@ -733,20 +731,6 @@ assert tz1 is tz2 - -@pytest.mark.smoke -@pytest.mark.tzoffset -def test_tzoffset_weakref(): - UTC1 = tz.tzoffset('UTC', 0) - UTC_ref = weakref.ref(tz.tzoffset('UTC', 0)) - UTC1 is UTC_ref() - del UTC1 - gc.collect() - - assert UTC_ref() is None - assert UTC_ref() is not tz.tzoffset('UTC', 0) - - @pytest.mark.tzoffset @pytest.mark.parametrize('args', [ ('UTC', 0), @@ -1053,7 +1037,6 @@ assert local1 is not local2 - @pytest.mark.gettz @pytest.mark.xfail(IS_WIN, reason='zoneinfo separately cached') def test_gettz_cache_clear(): @@ -1065,23 +1048,6 @@ assert NYC1 is not NYC2 -@pytest.mark.xfail(IS_WIN, reason="Windows does not use system zoneinfo") -@pytest.mark.smoke -@pytest.mark.gettz -def test_gettz_weakref(): - tz.gettz.cache_clear() - NYC1 = tz.gettz('America/New_York') - NYC_ref = weakref.ref(tz.gettz('America/New_York')) - - assert NYC1 is NYC_ref() - - del NYC1 - gc.collect() - - assert NYC_ref() is None - assert tz.gettz('America/New_York') is not NYC_ref() - - class ZoneInfoGettzTest(GettzTest, WarningTestMixin): def gettz(self, name): zoneinfo_file = zoneinfo.get_zonefile_instance() @@ -1409,21 +1375,6 @@ # Ensure that these still are all the same zone assert tz1 == tz2 == tz3 - -@pytest.mark.smoke -@pytest.mark.tzstr -def test_tzstr_weakref(): - tz_t1 = tz.tzstr('EST5EDT') - tz_t2_ref = weakref.ref(tz.tzstr('EST5EDT')) - assert tz_t1 is tz_t2_ref() - - del tz_t1 - gc.collect() - - assert tz_t2_ref() is None - assert tz.tzstr('EST5EDT') is not tz_t2_ref() - - @pytest.mark.tzstr @pytest.mark.parametrize('tz_str,expected', [ # From https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html diff --git a/dateutil/tz/_factories.py b/dateutil/tz/_factories.py index 13a32f627aa4c769f4564a4ceba0dd3c7ab8c879_ZGF0ZXV0aWwvdHovX2ZhY3Rvcmllcy5weQ==..18926353396b9fa1c36786e675cbd34d14bc5b1e_ZGF0ZXV0aWwvdHovX2ZhY3Rvcmllcy5weQ== 100644 --- a/dateutil/tz/_factories.py +++ b/dateutil/tz/_factories.py @@ -1,5 +1,5 @@ from datetime import timedelta -import weakref + class _TzSingleton(type): def __init__(cls, *args, **kwargs): @@ -19,7 +19,7 @@ class _TzOffsetFactory(_TzFactory): def __init__(cls, *args, **kwargs): - cls.__instances = weakref.WeakValueDictionary() + cls.__instances = {} def __call__(cls, name, offset): if isinstance(offset, timedelta): @@ -36,7 +36,7 @@ class _TzStrFactory(_TzFactory): def __init__(cls, *args, **kwargs): - cls.__instances = weakref.WeakValueDictionary() + cls.__instances = {} def __call__(cls, s, posix_offset=False): key = (s, posix_offset) diff --git a/dateutil/tz/tz.py b/dateutil/tz/tz.py index 13a32f627aa4c769f4564a4ceba0dd3c7ab8c879_ZGF0ZXV0aWwvdHovdHoucHk=..18926353396b9fa1c36786e675cbd34d14bc5b1e_ZGF0ZXV0aWwvdHovdHoucHk= 100644 --- a/dateutil/tz/tz.py +++ b/dateutil/tz/tz.py @@ -13,7 +13,6 @@ import sys import os import bisect -import weakref import six from six import string_types @@ -1529,7 +1528,7 @@ """ def __init__(self): - self.__instances = weakref.WeakValueDictionary() + self.__instances = {} self._cache_lock = _thread.allocate_lock() def __call__(self, name=None): @@ -1548,7 +1547,7 @@ def cache_clear(self): with self._cache_lock: - self.__instances = weakref.WeakValueDictionary() + self.__instances = {} @staticmethod def nocache(name=None):