decorators#
Decorators for FURY tests and functions.
This module provides decorators to handle doctests, parameter validation, and keyword-only arguments enforcement.
|
Replace custom skip test markup in doctests. |
|
Enforce keyword-only arguments. |
doctest_skip_parser#
- fury.decorators.doctest_skip_parser(func)[source]#
Replace custom skip test markup in doctests.
- Parameters:
func (callable) – Function whose docstring will be modified.
- Returns:
Function with modified docstring.
- Return type:
callable
Notes
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 theglobalsscope of func. For example, if the module globalHAVE_AMODULEis False, and module globalHAVE_BMODULEis 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]#
Enforce keyword-only arguments.
- Parameters:
- Returns:
Decorator function.
- Return type:
callable
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'