Decorators

flutils offers the following decorators:

@cached_property[source]

A property decorator that is only computed once per instance and then replaces itself with an ordinary attribute.

Deleting the attribute resets the property.

Note

In Python 3.8 the functools.cached_property decorator was added. It is recommended to use the built-in functools.cached_property; provided you’re using Python >= 3.8. cached_property remains for use with Python 3.6 and 3.7.

Example

Code:

from flutils.decorators import cached_property

class MyClass:

    def __init__(self):
        self.x = 5

    @cached_property
    def y(self):
        return self.x + 1

Usage:

>>> obj = MyClass()
>>> obj.y
6

New in version 0.2.0

This decorator is a derivative work of cached_property and is:

Copyright © 2015 Daniel Greenfeld; All Rights Reserved

Also this decorator is a derivative work of cached_property and is:

Copyright © 2011 Marcel Hellkamp