本文整理汇总了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={})