pg.typing.get_arg_fields

Accessible via pg.typing.get_arg_fields.

get_arg_fields(signature, args=None, args_docstr=None)[source]

Get schema fields for the arguments from a function or method signature.

Return type:

List[pg.Field]

Parameters:
  • signature – A Signature object.

  • args

    (Optional) explicit value specifications for the arguments, which is a list of tuples in: (<argumment-name>, <value-spec>, [description], [metadata-objects]).

    • argument-name - a string or a StrKey object. This name must exist in the signature’s argument list, unless the signature has a **kwargs, where the argument name can be an acceptable key in the dict that is passed to the **kwargs. If the argument name is a StrKey object, it specifies a field that matches any keys beyond the regular arguments for the **kwargs.

    • value-spec - a ValueSpec object asssociate with the argument name.

    • description - an optional string as the description for the argument.

    • metadata-objects - an optional list of any type, which can be used to generate code according to the schema.

  • args_docstr – (Optional) a dict of argument names to pg.object_utils.DocStrArgument object. If present, they will be used as the description for the Field objects.

Returns:

Field objects for the arguments from the signature in declaration order. If an argument is not present in args, it will be considered an Any. Otherwise it will create a Field from the explicit specifications. Default values for the arguments will be automatially propagated from the signature to the fields.

Raises:
  • KeyError – If argument names defined in args does not match with the arguments from the signature.

  • TypeError – The value spec defined in args is not compatible with the value spec inspected from the signature.

  • ValueError – The value spec defined in args does not align with the default values from the signature.