Python inspect.FullArgSpec() Examples
The following are 5
code examples of inspect.FullArgSpec().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
inspect
, or try the search function
.
Example #1
Source File: vevaluator.py From chainer-compiler with MIT License | 6 votes |
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
Example #2
Source File: test_methods.py From thermalprinter with MIT License | 5 votes |
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
Example #3
Source File: function_parser.py From tfx with Apache License 2.0 | 5 votes |
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)
Example #4
Source File: inspect.py From dragon with BSD 2-Clause "Simplified" License | 5 votes |
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={}, )
Example #5
Source File: utils.py From compare_gan with Apache License 2.0 | 5 votes |
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={})