dags.signature#

Module Contents#

Functions#

create_signature([args, kwargs])

Create a inspect.Signature object based on args and kwargs.

with_signature([func, args, kwargs, enforce])

Decorator that adds a signature to a function of type f(*args, **kwargs)

_fail_if_too_many_positional_arguments(present_args, ...)

_fail_if_duplicated_arguments(present_args, ...)

_fail_if_invalid_keyword_arguments(present_kwargs, ...)

rename_arguments([func, mapper])

Rename positional and keyword arguments of func.

dags.signature.create_signature(args=None, kwargs=None)[source]#

Create a inspect.Signature object based on args and kwargs.

Parameters
  • args (list or None) – The names of positional or keyword arguments.

  • kwargs (list or None) – The keyword only arguments.

Returns

inspect.Signature

dags.signature.with_signature(func=None, *, args=None, kwargs=None, enforce=True)[source]#

Decorator that adds a signature to a function of type f(*args, **kwargs)

Caveats: The created signature only contains the names of arguments and whether they are keyword only. There is no way of setting default values, type hints or other things.

Parameters
  • func (callable) – The function to be decorated. Should take *args and **kwargs as only arguments.

  • args (list or None) – The names of positional or keyword arguments.

  • kwargs (list or None) – The keyword only arguments.

  • enforce (bool) – Whether the signature should be enforced or just added to the function for introspection. This creates runtime overhead.

Returns

The function with signature.

Return type

function

dags.signature._fail_if_too_many_positional_arguments(present_args, argnames, funcname)[source]#
dags.signature._fail_if_duplicated_arguments(present_args, present_kwargs, funcname)[source]#
dags.signature._fail_if_invalid_keyword_arguments(present_kwargs, valid_kwargs, funcname)[source]#
dags.signature.rename_arguments(func=None, *, mapper=None)[source]#

Rename positional and keyword arguments of func.

Parameters
  • func (callable) – The function of which the arguments are renamed.

  • mapper (dict) – Dict of strings where keys are old names and values are new of arguments.

Returns

The function with renamed arguments.

Return type

function