Signature Tools¶
Tools to extract a method’s signature and it’s components from an argspec.
-
hoft.core.sigs.
num_keywords
(argspec)[source]¶ Determine the number of keyword arguments (eg: def func(name=value)).
Parameters: argspec (inspect.ArgSpec) – A previously obtained argspec. Returns: Number of positional arguments. Return type: int
-
hoft.core.sigs.
num_positionals
(argspec, num_keyword_args=None)[source]¶ Determine the number of positional arguments (eg: def func(name)).
Parameters: - argspec (inspect.ArgSpec) – A previously obtained argspec.
- num_keyword_args (int) – Number of keyword arguments already known (if any, if not then they will be calculated).
Returns: Number of positional arguments.
Return type: int
-
hoft.core.sigs.
get_keywords
(argspec, num_positional_args=None)[source]¶ Get all keyword arguments and their associated default values.
Parameters: - argspec (inspect.ArgSpec) – A previously obtained argspec.
- num_positional_args (int) – Number of positional arguments already known (if any, if not then they will be calculated).
Returns: A dictionary containing the keyword names and their associated default values.
Return type: Dict[str, int]
-
hoft.core.sigs.
get_positionals
(argspec, num_positional_args=None)[source]¶ Get all positional arguments.
Parameters: - argspec (inspect.ArgSpec) – A previously obtained argspec.
- num_positional_args (int) – Number of positional arguments already known (if any, if not then they will be calculated).
Returns: A list containing the positional arguments in declaration order.
Return type: List[str]
-
hoft.core.sigs.
get_default_value
(name, argspec)[source]¶ Get the default value for the keyword argument of name.
Parameters: - name (str) – The name to get the default keyword argument value for.
- argspec (inspect.ArgSpec) – A previously obtained argspec.
Returns: The default_value present in the method’s signature.
Raises: NoDefaultError When no default value can or does exist fo the name.
-
hoft.core.sigs.
get_signature
(argspec)[source]¶ Obtain a Signature from an argspec
Parameters: argspec (inspect.ArgSpec) – A previously obtained argspec. Returns: The signature. Return type: Signature
-
hoft.core.sigs.
signature
(func)[source]¶ Obtain a method’s Signature.
Parameters: func (callable) – Method to obtain the signature for. Returns: The method’s signature. Return type: Signature
Note
Main hoft.core.utils.Signature represents the main definition of a method’s signature
-
hoft.core.utils.
Signature
(args, vaargs, kwargs, keywords)¶ A Signature representing a parsed argspec for a function:
Parameters: - args (list) – The positional argument names.
- vaargs (Union[string|None]) – The positional varargs name (eg after a *).
- kwargs (dict) – The keyword argument names and associated default values.
- keywords (Union[string|None]) – The keyword varkwargs name (eg: after a **).
- Example:
- def func(a, b, c=1, **d) === Signature([‘a’, ‘b’], None, {‘c’: 1}, ‘d’)