decorators#

Decorators for FURY tests.

SKIP_RE

Compiled regular expression object.

doctest_skip_parser(func)

Decorator replaces custom skip test markup in doctests.

warn_on_args_to_kwargs([from_version, ...])

Decorator to enforce keyword-only arguments.

SKIP_RE#

fury.decorators.SKIP_RE#

Compiled regular expression object.

doctest_skip_parser#

fury.decorators.doctest_skip_parser(func)[source]#

Decorator replaces custom skip test markup in doctests.

Say a function has a docstring:

something # skip if not HAVE_AMODULE
something + else
something # skip if HAVE_BMODULE

This decorator will evaluate the expression after skip if. If this evaluates to True, then the comment is replaced by # doctest: +SKIP. If False, then the comment is just removed. The expression is evaluated in the globals scope of func. For example, if the module global HAVE_AMODULE is False, and module global HAVE_BMODULE is False, the returned function will have docstring:

something # doctest: +SKIP
something + else
something

warn_on_args_to_kwargs#

fury.decorators.warn_on_args_to_kwargs(from_version='0.11.0', until_version='0.14.0')[source]#

Decorator to enforce keyword-only arguments.

This decorator enforces that all arguments after the first one are keyword-only arguments. It also checks that all keyword arguments are expected by the function.

Parameters:
from_version: str, optional

The version of fury from which the function was supported.

until_version: str, optional

The version of fury until which the function was supported.

Returns:
decorator: Callable

Decorator function.

Examples

>>> from fury.decorators import warn_on_args_to_kwargs
>>> import fury
>>> @warn_on_args_to_kwargs()
... def f(a, b, *, c, d=1, e=1):
...     return a + b + c + d + e
>>> CURRENT_VERSION = fury.__version__
>>> fury.__version__ = "0.11.0"
>>> f(1, 2, 3, 4, 5)
15
>>> f(1, 2, c=3, d=4, e=5)
15
>>> f(1, 2, 2, 4, e=5)
14
>>> f(1, 2, c=3, d=4)
11
>>> f(1, 2, d=3, e=5)
Traceback (most recent call last):
...
TypeError: f() missing 1 required keyword-only argument: 'c'