Skip to content

Commit

Permalink
Rely on cached_property to cache values on the instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Sep 13, 2024
1 parent eefac29 commit e23cbba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions newsfragments/+f9a115e5.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rely on cached_property to cache values on the instance.
20 changes: 11 additions & 9 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
for more detail.
"""

import contextlib
import functools
import io
import itertools
import pathlib
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit e23cbba

Please sign in to comment.