typedargs.metadata module¶
The basic class that is used to store metadata about a function.
Summary¶
Classes:
AnnotatedMetadata |
All of the associated metadata for an annotated function or class. |
Reference¶
-
class
typedargs.metadata.
AnnotatedMetadata
(func, name=None)[source]¶ Bases:
object
All of the associated metadata for an annotated function or class.
Parameters: - func (callable) – The function that we are annotated so that we can pull out relevant argument spec information. If func is a class, we pull arguments from its __init__ routine
- name (str) – An optional name that will overwrite the default name of this function
-
spec_filled
(pos_args, kw_args)[source]¶ Check if we have enough arguments to call this function.
Parameters: Returns: True if we have a filled spec, False otherwise.
Return type:
-
add_param
(name, type_class, type_name, validators, desc=None)[source]¶ Add type information for a parameter by name.
Parameters: - name (str) – The name of the parameter we wish to annotate
- type_class (type) – Parameter type class
- type_name (str) – The name of the parameter’s type
- validators (list) – A list of either strings or n tuples that each specify a validator defined for type_name. If a string is passed, the validator is invoked with no extra arguments. If a tuple is passed, the validator will be invoked with the extra arguments.
- desc (str) – Optional parameter description.
-
typed_returnvalue
(type_name, formatter=None)[source]¶ Add type information to the return value of this function.
Parameters:
-
custom_returnvalue
(printer, desc=None)[source]¶ Use a custom function to print the return value.
Parameters: - printer (callable) – A function that should take in the return value and convert it to a string.
- desc (str) – An optional description of the return value.
-
match_shortname
(name, filled_args=None)[source]¶ Try to convert a prefix into a parameter name.
If the result could be ambiguous or there is no matching parameter, throw an ArgumentError
Parameters: Returns: The full matching parameter name
Return type:
-
param_type
(name: str) → Union[type, str, None][source]¶ Get the parameter type information by name.
Parameters: name (str) – The full name of a parameter. Returns: The type name or None if no type information is given. Return type: str
-
signature
(name=None)[source]¶ Return our function signature as a string.
By default this function uses the annotated name of the function however if you need to override that with a custom name you can pass name=<custom name>
Parameters: name (str) – Optional name to override the default name given in the function signature. Returns: The formatted function signature Return type: str
-
format_returnvalue
(value)[source]¶ Format the return value of this function as a string.
Parameters: value (object) – The return value that we are supposed to format. Returns: - The formatted return value, or None if this function indicates
- that it does not return data
Return type: str
-
convert_positional_argument
(index, arg_value)[source]¶ Convert and validate a positional argument.
Parameters: Returns: The converted value.
Return type:
-
check_spec
(pos_args, kwargs=None)[source]¶ Check if there are any missing or duplicate arguments.
Parameters: Returns: - A dictionary of argument name to argument value, pulled from either
the value passed or the default value if no argument is passed.
Return type: Raises: ArgumentError
– If a positional or keyword argument does not fit in the spec.ValidationError
– If an argument is passed twice.