MCPcopy Create free account
hub / github.com/SooLab/CGFormer / cached_property

Class cached_property

bert/file_utils.py:764–784  ·  view source on GitHub ↗

Descriptor that mimics @property but caches output in member variable. From tensorflow_datasets Built-in in functools from Python 3.8.

Source from the content-addressed store, hash-verified

762
763
764class cached_property(property):
765 """
766 Descriptor that mimics @property but caches output in member variable.
767
768 From tensorflow_datasets
769
770 Built-in in functools from Python 3.8.
771 """
772
773 def __get__(self, obj, objtype=None):
774 # See docs.python.org/3/howto/descriptor.html#properties
775 if obj is None:
776 return self
777 if self.fget is None:
778 raise AttributeError("unreadable attribute")
779 attr = "__cached_" + self.fget.__name__
780 cached = getattr(obj, attr, None)
781 if cached is None:
782 cached = self.fget(obj)
783 setattr(obj, attr, cached)
784 return cached
785
786
787def torch_required(func):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected