pg.typing.Signature¶
Accessible via pg.typing.Signature.
- class Signature(callable_type, name, module_name, args=None, kwonlyargs=None, varargs=None, varkw=None, return_value=None, qualname=None, description=None)[source]¶
Bases:
pg.FormattablePY3 function signature.
Methods:
annotate([args, return_value])Annotate arguments with extra typing.
fields([remove_self, include_return])Returns the fields of this signature.
format([compact, verbose, root_indent])Format current object.
from_callable(callable_object[, ...])Creates Signature from a callable object.
from_schema(schema, module_name, name[, ...])Creates a signature from a schema object.
from_signature(sig, name, callable_type[, ...])Returns PyGlove signature from Python signature.
get_value_spec(name)Returns Value spec for an argument name.
make_function(body[, exec_globals, exec_locals])Makes a function with current signature.
to_schema([remove_self, include_return])Returns the schema of this signature.
Attributes:
Returns names of all arguments according to their declaration order.
Returns whether wildcard positional argument is present.
Returns whether wildcard keyword argument is present.
Returns whether any wildcard arguments are present.
Returns ID of the function.
Returns all named arguments according to their declaration order.
- format(compact=False, verbose=True, root_indent=0, **kwargs)[source]¶
Format current object.
- Return type:
- classmethod from_callable(callable_object, auto_typing=False, auto_doc=False)[source]¶
Creates Signature from a callable object.
- Return type:
- classmethod from_schema(schema, module_name, name, qualname=None, is_method=True)[source]¶
Creates a signature from a schema object.
- Return type:
- Parameters:
schema – A pg.typing.Schema object associated with a pg.Object.
module_name – Module name for the signature.
name – Function or method name of the signature.
qualname – Qualname of the signature.
is_method – If True, self will be added in the signature as the first argument.
- Returns:
A signature object from the schema.
- classmethod from_signature(sig, name, callable_type, module_name=None, qualname=None, auto_typing=False, docstr=None, parent_module=None)[source]¶
Returns PyGlove signature from Python signature.
- Return type:
- Parameters:
sig – Python signature.
name – Name of the entity (class name or function/method name).
callable_type – the type of this callable.
module_name – Module name of the entity.
qualname – (Optional) qualified name of the entity.
auto_typing – If True, automatically convert argument annotations to PyGlove ValueSpec objects. Otherwise use pg.typing.Any() with annotations.
docstr – (Optional) DocStr for this entity.
parent_module – (Optional) Parent module from where the signature is derived. This is useful to infer classes with forward declarations.
- Returns:
A PyGlove Signature object.
- get_value_spec(name)[source]¶
Returns Value spec for an argument name.
- Return type:
- Parameters:
name – Argument name.
- Returns:
ValueSpec for the requested argument. If name is not found, value spec of wildcard keyword argument will be used. None will be returned if name does not exist in signature and wildcard keyword is not accepted.
- make_function(body, exec_globals=None, exec_locals=None)[source]¶
Makes a function with current signature.