Skip to main content

cached_property

Decorator that converts a method with a single self argument into a property cached on the instance.

Attributes

AttributeTypeDescription
namestring = NoneThe name of the attribute as it appears on the owner class, used to store the computed value in the instance's dictionary.

Constructor

Signature

def cached_property(
func: callable
) - > null

Parameters

NameTypeDescription
funccallableThe method to be converted into a cached property.

Methods


func()

@classmethod
def func(
instance: object
) - > null

Raises a TypeError to prevent usage of the cached_property before it has been properly initialized via set_name.

Parameters

NameTypeDescription
instanceobjectThe class instance the property is being accessed on

Returns

TypeDescription
null