本文整理匯總了Python中inspect.FullArgSpec方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.FullArgSpec方法的具體用法?Python inspect.FullArgSpec怎麽用?Python inspect.FullArgSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類inspect
的用法示例。
在下文中一共展示了inspect.FullArgSpec方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: veval_ast_arguments
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FullArgSpec [as 別名]
def veval_ast_arguments(astc : 'AstContext', local_field : 'values.Field', graph : 'Graph', context : 'functions.VEvalContext' = None):
assert(isinstance(astc.nast, gast.gast.arguments))
lineprop = utils.LineProperty(astc.lineno, astc.filename)
ret = functions.FunctionArgCollection()
argspec = inspect.FullArgSpec(astc.nast.args, astc.nast.vararg, astc.nast.kwarg,
astc.nast.defaults, astc.nast.kwonlyargs, astc.nast.kw_defaults, None)
assert not argspec.kwonlyargs, "Keyword only args are not supported"
assert not argspec.varargs, "Varaibale arguments *args is not supported"
assert not argspec.varkw, "Variable keywords **kwargs is not supported"
defaults = [veval_ast(astc.c(default), local_field, graph, context) for default in argspec.defaults]
arg_list = []
for k, v in itertools.zip_longest(reversed(argspec.args), defaults):
arg_list.append((k.id, v))
# reverse the list
for k, v in reversed(arg_list):
ret.add_arg(k, v)
return ret
示例2: test_signature
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FullArgSpec [as 別名]
def test_signature(methods, method, arguments):
methods.remove(method)
args = {"args": ["self"], "varargs": None, "varkw": None,
"defaults": None, "kwonlyargs": [],
"kwonlydefaults": None, "annotations": {},
**arguments}
sig = inspect.FullArgSpec(**args)
spec = inspect.getfullargspec(getattr(ThermalPrinter, method))
assert spec == sig
示例3: _validate_signature
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FullArgSpec [as 別名]
def _validate_signature(
func: types.FunctionType,
argspec: inspect.FullArgSpec, # pytype: disable=module-attr
typehints: Dict[Text, Any],
subject_message: Text) -> None:
"""Validates signature of a typehint-annotated component executor function."""
args, varargs, keywords = argspec.args, argspec.varargs, argspec.varkw
if varargs or keywords:
raise ValueError('%s does not support *args or **kwargs arguments.' %
subject_message)
# Validate argument type hints.
for arg in args:
if isinstance(arg, list):
# Note: this feature was removed in Python 3:
# https://www.python.org/dev/peps/pep-3113/.
raise ValueError('%s does not support nested input arguments.' %
subject_message)
if arg not in typehints:
raise ValueError('%s must have all arguments annotated with typehints.' %
subject_message)
# Validate return type hints.
if isinstance(typehints.get('return', None), annotations.OutputDict):
for arg, arg_typehint in typehints['return'].kwargs.items():
if (isinstance(arg_typehint, annotations.OutputArtifact) or
(inspect.isclass(arg_typehint) and
issubclass(arg_typehint, artifact.Artifact))):
raise ValueError(
('Output artifacts for the component executor function %r should '
'be declared as function parameters annotated with type hint '
'`tfx.types.annotations.OutputArtifact[T]` where T is a '
'subclass of `tfx.types.Artifact`. They should not be declared '
'as part of the return value `OutputDict` type hint.') % func)
elif 'return' not in typehints or typehints['return'] in (None, type(None)):
pass
else:
raise ValueError(
('%s must have either an OutputDict instance or `None` as its return '
'value typehint.') % subject_message)
示例4: _convert_maybe_argspec_to_fullargspec
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FullArgSpec [as 別名]
def _convert_maybe_argspec_to_fullargspec(argspec):
if isinstance(argspec, FullArgSpec):
return argspec
return FullArgSpec(
args=argspec.args,
varargs=argspec.varargs,
varkw=argspec.keywords,
defaults=argspec.defaults,
kwonlyargs=[],
kwonlydefaults=None,
annotations={},
)
示例5: _getfullargspec
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import FullArgSpec [as 別名]
def _getfullargspec(fn):
"""Python 2/3 compatible version of the inspect.getfullargspec method.
Args:
fn: The function object.
Returns:
A FullArgSpec. For Python 2 this is emulated by a named tuple.
"""
arg_spec_fn = inspect.getfullargspec if six.PY3 else inspect.getargspec
try:
arg_spec = arg_spec_fn(fn)
except TypeError:
# `fn` might be a callable object.
arg_spec = arg_spec_fn(fn.__call__)
if six.PY3:
assert isinstance(arg_spec, _FullArgSpec)
return arg_spec
return _FullArgSpec(
args=arg_spec.args,
varargs=arg_spec.varargs,
varkw=arg_spec.keywords,
defaults=arg_spec.defaults,
kwonlyargs=[],
kwonlydefaults=None,
annotations={})