tet.decorators package

Decorator utilities for Tet applications.

This module provides useful decorators:

Example

Marking a function as deprecated:

from tet.decorators import deprecated

@deprecated
def old_function():
    pass

Using reify_attr for cached properties:

from tet.decorators import reify_attr

class MyClass:
    @reify_attr
    def expensive_computation(self):
        # This will only be called once per instance
        return compute_something()
tet.decorators.deprecated(func)[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

class tet.decorators.reify_attr(wrapped)[source]

Bases: object

A cached property descriptor that uses the actual attribute name.

Unlike Pyramid’s reify which gets the attribute name from the decorated method, reify_attr uses the name of the actual attribute it’s assigned to. This is determined via __set_name__, falling back to finding the attribute on the class if __set_name__ is not called (e.g., when the descriptor is assigned dynamically).

This pattern is useful as a building block for descriptors like autowired in pyramid_di, where the descriptor needs to know its attribute name to cache the resolved value on the instance.