Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
decorators module

Class and function decorators.

## cacheable function

    cacheable(
        *args,
        use_cache=False,
        whitelist=False,
        max_size=None,
        ignore_args=None,
        **options
    )

Cacheable function decorator.

See notes on cacheable_property.

Note

To decorate an instance method, use cacheable_method().

## cacheable_method function

    cacheable_method(
        *args,
        use_cache=False,
        whitelist=False,
        max_size=None,
        ignore_args=None,
        **options
    )

Cacheable method decorator.

See notes on cacheable_property.

## cached function

    cached(
        *args,
        **options
    )

cacheable() with `use_cache` set to True.

Note

To decorate an instance method, use cached_method().

## cached_method function

    cached_method(
        *args,
        **options
    )

cacheable_method() with `use_cache` set to True.

## custom_function function

    custom_function(
        *args,
        **options
    )

Custom function decorator.

## custom_method function

    custom_method(
        *args,
        **options
    )

Custom method decorator.

## cacheable_functionT class

    cacheable_functionT(
        *args,
        **kwargs
    )

Base class for protocol classes.

Protocol classes are defined as::

    class Proto(Protocol):
        def meth(self) -> int:
            ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

__ class C__

    def meth(self) -> int:
        return 0

def func(x: Proto) -> int: return x.meth()

func(C()) # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

    class GenProto(Protocol[T]):
        def meth(self) -> T:
            ...

Superclasses

- custom_functionT
- `typing.Generic`
- `typing.Protocol`

### get_ca_setup class variable

### is_cacheable class variable

## cacheable_methodT class

    cacheable_methodT(
        *args,
        **kwargs
    )

Base class for protocol classes.

Protocol classes are defined as::

    class Proto(Protocol):
        def meth(self) -> int:
            ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

__ class C__

    def meth(self) -> int:
        return 0

def func(x: Proto) -> int: return x.meth()

func(C()) # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

    class GenProto(Protocol[T]):
        def meth(self) -> T:
            ...

Superclasses

- custom_functionT
- custom_methodT
- `typing.Generic`
- `typing.Protocol`

### get_ca_setup class variable

## cacheable_property class

    cacheable_property(
        func,
        use_cache=False,
        whitelist=False,
        **options
    )

Extends custom_property for cacheable properties.

Note

Assumes that the instance (provided as `self`) won't change. If calculation depends upon object attributes that can be changed, it won't notice the change.

Superclasses

- `builtins.property`
- custom_property

Inherited members

- custom_property.func
- custom_property.name
- custom_property.options

Subclasses

- cached_property

### get_ca_setup method

    cacheable_property.get_ca_setup(
        instance=None
    )

Get setup of type CARunSetup if instance is known, or CAUnboundSetup otherwise.

See vectorbtpro.registries.ca_registry for details on the caching procedure.

### init_use_cache property

Initial value for `use_cache`.

### init_whitelist property

Initial value for `whitelist`.

## cached_property class

    cached_property(
        func,
        **options
    )

cacheable_property with `use_cache` set to True.

Superclasses

- `builtins.property`
- cacheable_property
- custom_property

Inherited members

- cacheable_property.func
- cacheable_property.get_ca_setup()
- cacheable_property.init_use_cache
- cacheable_property.init_whitelist
- cacheable_property.name
- cacheable_property.options

## class_or_instanceproperty class

    class_or_instanceproperty(
        func
    )

Property that binds `self` to a class if the function is called as class method, otherwise to an instance.

### func property

Wrapped function.

## classproperty class

    classproperty(
        func
    )

Property that can be called on a class.

### func property

Wrapped function.

## custom_functionT class

    custom_functionT(
        *args,
        **kwargs
    )

Base class for protocol classes.

Protocol classes are defined as::

    class Proto(Protocol):
        def meth(self) -> int:
            ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

__ class C__

    def meth(self) -> int:
        return 0

def func(x: Proto) -> int: return x.meth()

func(C()) # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

    class GenProto(Protocol[T]):
        def meth(self) -> T:
            ...

Superclasses

- `typing.Generic`
- `typing.Protocol`

Subclasses

- cacheable_functionT
- custom_methodT

### func class variable

### is_method class variable

### name class variable

### options class variable

## custom_methodT class

    custom_methodT(
        *args,
        **kwargs
    )

Base class for protocol classes.

Protocol classes are defined as::

    class Proto(Protocol):
        def meth(self) -> int:
            ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

__ class C__

    def meth(self) -> int:
        return 0

def func(x: Proto) -> int: return x.meth()

func(C()) # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

    class GenProto(Protocol[T]):
        def meth(self) -> T:
            ...

Superclasses

- custom_functionT
- `typing.Generic`
- `typing.Protocol`

Subclasses

- cacheable_methodT

## custom_property class

    custom_property(
        func,
        **options
    )

Custom extensible property that stores function and options as attributes.

Note

custom_property instances belong to classes, not class instances. Thus changing the property will do the same for each instance of the class where the property has been defined initially.

Superclasses

- `builtins.property`

Subclasses

- cacheable_property

### func property

Wrapped function.

### name property

Wrapped function name.

### options property

Options.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings