diff --git a/newsfragments/+f9a115e5.feature.rst b/newsfragments/+f9a115e5.feature.rst new file mode 100644 index 0000000..8e692a2 --- /dev/null +++ b/newsfragments/+f9a115e5.feature.rst @@ -0,0 +1 @@ +Rely on cached_property to cache values on the instance. \ No newline at end of file diff --git a/zipp/__init__.py b/zipp/__init__.py index 20b6d04..d5b96b8 100644 --- a/zipp/__init__.py +++ b/zipp/__init__.py @@ -7,7 +7,7 @@ for more detail. """ -import contextlib +import functools import io import itertools import pathlib @@ -181,16 +181,18 @@ class FastLookup(CompleteDirs): """ def namelist(self): - with contextlib.suppress(AttributeError): - return self.__names - self.__names = super().namelist() - return self.__names + return self._namelist + + @functools.cached_property + def _namelist(self): + return super().namelist() def _name_set(self): - with contextlib.suppress(AttributeError): - return self.__lookup - self.__lookup = super()._name_set() - return self.__lookup + return self._name_set_prop + + @functools.cached_property + def _name_set_prop(self): + return super()._name_set() def _extract_text_encoding(encoding=None, *args, **kwargs):