MCPcopy Create free account
hub / github.com/pyca/cryptography / cached_property

Function cached_property

src/cryptography/utils.py:108–120  ·  view source on GitHub ↗
(func: typing.Callable)

Source from the content-addressed store, hash-verified

106
107
108def cached_property(func: typing.Callable) -> property:
109 cached_name = f"_cached_{func}"
110 sentinel = object()
111
112 def inner(instance: object):
113 cache = getattr(instance, cached_name, sentinel)
114 if cache is not sentinel:
115 return cache
116 result = func(instance)
117 setattr(instance, cached_name, result)
118 return result
119
120 return property(inner)
121
122
123# Python 3.10 changed representation of enums. We use well-defined object

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected