lingvo.core.inspect_utils module
Utilities to bind function signatures to params.
- lingvo.core.inspect_utils._IsDefinableParameter(parameter)[source]
Checks if the parameter can be defined in
Params.- Parameters
parameter – inspect.Parameter to be checked.
- Returns
True if the
parameter’s kind is eitherPOSITIONAL_OR_KEYWORDorKEYWORD_ONLYwhich are definable inParams, False if it is eitherVAR_POSITIONALorVAR_KEYWORDwhich are ignorable.- Raises
ValueError – The
parameterhas another kind which are possibly not supported, e.g.,POSITIONAL_ONLYparameters.
- lingvo.core.inspect_utils._ExtractParameters(func, ignore, bound)[source]
Extracts parameters of func which can be defined in Params.
- Parameters
func – A callable to be analysed.
ignore – A collection of parameter names in
functo be ignored.bound – Whether the
funcis used as a bound function (an object method or a class method) or not. If True, the first parameter of thefuncwill be ignored.
- Returns
A generator of
inspect.Parameterrepresenting definable parameters.
- lingvo.core.inspect_utils.DefineParams(func, params, ignore=None, bound=False)[source]
Defines params for each parameter of given callable.
This allows you to define the parameters necessary to call a callable without having to type the Define statements yourself. Default values for the function parameters will be copied into the params object as well.
To use this function for analysing a class instantiation, users usually can pass the class type as the
func. If it does not work correctly, pass the__init__method of the class withbound=Trueinstead.- Parameters
func – A callable to be analysed. Parameters of this function will be defined in
params. This function expects thatfuncmaintains the explicit signature of its parameters. Implicit parameters that are stored in*argsor**kwargscould not be analysed correctly.params – A
Paramsobject to be updated. New parameters will be defined here.ignore – A collection of parameter names in
functo be ignored from defining corresponding entries inparams.bound – Whether
funcwill be used as a bound function (an object method or a class method) or not. If True, the first parameter offunc(typicallyselforcls) will be ignored.
- lingvo.core.inspect_utils._MakeArgs(func, params, **kwargs)[source]
Generates an argument list to call func.
- Parameters
func – A callable to be called.
params – A Params object containing arguments for
func.**kwargs – Argument/value pairs that should override params.
- Returns
A dict containing function parameters to be used as
**kwargsoffunc.
- lingvo.core.inspect_utils.CallWithParams(func, params, **kwargs)[source]
Call a function or method with a Params object.
- Parameters
func – A callable to be called.
params – A Params object containing parameters of
func.**kwargs – Argument/value pairs that should override
params.
- Returns
The return values from func.
- lingvo.core.inspect_utils.ConstructWithParams(cls, params, **kwargs)[source]
Constructs a class object with a Params object.
- Parameters
cls – A class type to be constructed.
params – A Params object containing parameters of
cls.__init__.**kwargs – Argument/value pairs that should override
params.
- Returns
The constructed object.