Skip to content

Commit

Permalink
Merge pull request #32 from ronaldokun/sourcery/pull-31
Browse files Browse the repository at this point in the history
Add support for caching in Python 3.10 and above. (Sourcery refactored)
  • Loading branch information
ronaldokun authored Nov 9, 2023
2 parents e986051 + f1a140d commit ad4b016
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rfpye/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,17 @@ def getattrs(obj: Any, attrs: Iterable = None, as_tuple=False) -> L:

# Cell
def cached(f):
version = float(platform.python_version()[:3])
if version >= 3.8:
version_list = platform.python_version().split(".")
major_version = int(version_list[0])
if major_version < 3:
raise NotImplementedError(
"There is no cache attribute implemented for python < 3"
)
minor_version = int(version_list[1])

if minor_version >= 8:
return functools.cached_property(f)
elif version >= 3.2:
elif minor_version >= 2:
return property(functools.lru_cache()(f))
else:
raise NotImplementedError(
Expand Down

0 comments on commit ad4b016

Please sign in to comment.