Signature#

signature module#

mmodel.signature.add_signature(func, inputs)[source]#

Add signature to ufunc and builtin function.

Numpy’s ufunc and builtin type do not have signatures, therefore, a new signature is created, and the input arguments are mapped as positional-only values.

Parameters:
  • func (callable) – function to change signature

  • inputs (list) – new input parameters for the function.

mmodel.signature.check_signature(func)[source]#

Check if the function signature has parameters with default values.

If the function has position-only, or var-positional, or var-keyword, or default values, the function returns False.

mmodel.signature.convert_signature(func)[source]#

Convert function signature to pos_or_keywords.

The method ignores “args”, and “kwargs”. Note the signature does not include parameters with default values. Use inputs to include the parameters.

mmodel.signature.has_signature(func)[source]#

Check if the function has a signature.

The function checks if the function has a signature. If the function has a signature, the function returns True. If the function does not have a signature, the function returns False.

mmodel.signature.modify_signature(func, inputs)[source]#

Modify function signature to custom-defined inputs.

The inputs replace the original signature in the same order. The resulting function is a keyword-only function. The conversion ignores VAR_POSITIONAL (args). For these functions, create a new function instead.

Parameters:
  • func (callable) – function to change signature

  • inputs (list) – new input parameters for the function.

mmodel.signature.restructure_signature(signature, default_dict, kind=_ParameterKind.POSITIONAL_OR_KEYWORD)[source]#

Add defaults to signature for Model.

Here the parameter kinds are replaced with kind (defaults to POSITIONAL_OR_KEYWORD), and defaults are applied. The final signatures are sorted. The function is used in the Model signature definition, therefore no VAR_POSITIONAL or VAR_KEYWORD should be in the signature.

Parameters:
  • signature (inspect.Signature) – signature to add defaults

  • default_dict (dict) – default values for the parameters

  • kind (int) – parameter kind

mmodel.signature.split_arguments(sig, arguments)[source]#

Split the input argument into args and kwargs based on the signature.

The kwargs need to match the inputs completely. The function takes care of the position-only variable in the old function.

Parameters:
  • sig (inspect.Signature) – signature of the original function

  • arguments (dict) – keyword argument values