macrosynergy.management.decorators#

Module housing decorators that are used to validate the arguments and return values of functions.

deprecate(new_func, deprecate_version, remove_after=None, message=None, macrosynergy_package_version='1.2.3')[source]#

Decorator for deprecating a function.

Parameters:
  • new_func (callable) – The function that replaces the old one.

  • deprecate_version (str) – The version in which the old function is deprecated.

  • remove_after (str) – The version in which the old function is removed.

  • message (str) – The message to display when the old function is called. This message must contain the following format strings: “{old_method}”, “{deprecate_version}”, and “{new_method}”. If None, the default message is used.

  • macrosynergy_package_version (str) – The version of the macrosynergy package. This is used to determine if the deprecation warning should be shown.

Returns:

The decorated function.

Return type:

callable

is_matching_subscripted_type(value, type_hint)[source]#

Implementation of insinstance() for type-hints imported from the typing module, and for subscripted types (e.g. List[int], Tuple[str, int], etc.).

Parameters:
  • value (Any) – The value to check.

  • type_hint (Type[Any]) – The type hint to check against.

Returns:

True if the value is of the type hint, False otherwise.

Return type:

bool

get_expected_type(arg_type_hint)[source]#

Based on the type hint, return a list of strings that represent the type hint - including any nested type hints.

Parameters:

arg_type_hint (Type[Any]) – The type hint to get the expected types for.

Returns:

A list of strings that represent the type hint.

Return type:

List[str]

argvalidation(func)[source]#

Decorator for validating the arguments and return value of a function.

Parameters:

func (Callable[..., Any]) – The function to validate.

Returns:

The decorated function.

Return type:

Callable[…, Any]

argcopy(func)[source]#

Decorator for applying a “pass-by-value” method to the arguments of a function.

Parameters:

func (Callable) – The function to copy arguments for.

Returns:

The decorated function.

Return type:

Callable