Python inspect.CO_VARKEYWORDS Examples
The following are 27
code examples of inspect.CO_VARKEYWORDS().
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: compat.py From android_universal with MIT License | 6 votes |
def inspect_func_args(fn): if py3k: co = fn.__code__ else: co = fn.func_code nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) varargs = None if co.co_flags & CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & CO_VARKEYWORDS: varkw = co.co_varnames[nargs] if py3k: return args, varargs, varkw, fn.__defaults__ else: return args, varargs, varkw, fn.func_defaults
Example #2
Source File: compat.py From jbox with MIT License | 6 votes |
def inspect_func_args(fn): if py3k: co = fn.__code__ else: co = fn.func_code nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) varargs = None if co.co_flags & CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & CO_VARKEYWORDS: varkw = co.co_varnames[nargs] if py3k: return args, varargs, varkw, fn.__defaults__ else: return args, varargs, varkw, fn.func_defaults
Example #3
Source File: compat.py From teleport with Apache License 2.0 | 6 votes |
def inspect_func_args(fn): if py3k: co = fn.__code__ else: co = fn.func_code nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) varargs = None if co.co_flags & CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & CO_VARKEYWORDS: varkw = co.co_varnames[nargs] if py3k: return args, varargs, varkw, fn.__defaults__ else: return args, varargs, varkw, fn.func_defaults
Example #4
Source File: compat.py From ansible-cmdb with GNU General Public License v3.0 | 6 votes |
def inspect_func_args(fn): if py3k: co = fn.__code__ else: co = fn.func_code nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) varargs = None if co.co_flags & CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & CO_VARKEYWORDS: varkw = co.co_varnames[nargs] if py3k: return args, varargs, varkw, fn.__defaults__ else: return args, varargs, varkw, fn.func_defaults
Example #5
Source File: compat.py From docassemble with MIT License | 6 votes |
def inspect_func_args(fn): if py3k: co = fn.__code__ else: co = fn.func_code nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) varargs = None if co.co_flags & CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & CO_VARKEYWORDS: varkw = co.co_varnames[nargs] if py3k: return args, varargs, varkw, fn.__defaults__ else: return args, varargs, varkw, fn.func_defaults
Example #6
Source File: capture_collector.py From cloud-debug-python with Apache License 2.0 | 6 votes |
def CaptureFrameLocals(self, frame): """Captures local variables and arguments of the specified frame. Args: frame: frame to capture locals and arguments. Returns: (arguments, locals) tuple. """ # Capture all local variables (including method arguments). variables = {n: self.CaptureNamedVariable(n, v, 1, self.default_capture_limits) for n, v in six.viewitems(frame.f_locals)} # Split between locals and arguments (keeping arguments in the right order). nargs = frame.f_code.co_argcount if frame.f_code.co_flags & inspect.CO_VARARGS: nargs += 1 if frame.f_code.co_flags & inspect.CO_VARKEYWORDS: nargs += 1 frame_arguments = [] for argname in frame.f_code.co_varnames[:nargs]: if argname in variables: frame_arguments.append(variables.pop(argname)) return (frame_arguments, list(six.viewvalues(variables)))
Example #7
Source File: params.py From cauldron with MIT License | 6 votes |
def get_kwargs_index(target) -> int: """ Returns the index of the "**kwargs" parameter if such a parameter exists in the function arguments or -1 otherwise. :param target: The target function for which the kwargs index should be determined :return: The keyword arguments index if it exists or -1 if not """ code = target.__code__ if not bool(code.co_flags & inspect.CO_VARKEYWORDS): return -1 return ( code.co_argcount + code.co_kwonlyargcount + (1 if code.co_flags & inspect.CO_VARARGS else 0) )
Example #8
Source File: langhelpers.py From sqlalchemy with MIT License | 6 votes |
def _inspect_func_args(fn): try: co_varkeywords = inspect.CO_VARKEYWORDS except AttributeError: # https://docs.python.org/3/library/inspect.html # The flags are specific to CPython, and may not be defined in other # Python implementations. Furthermore, the flags are an implementation # detail, and can be removed or deprecated in future Python releases. spec = compat.inspect_getfullargspec(fn) return spec[0], bool(spec[2]) else: # use fn.__code__ plus flags to reduce method call overhead co = fn.__code__ nargs = co.co_argcount return ( list(co.co_varnames[:nargs]), bool(co.co_flags & co_varkeywords), )
Example #9
Source File: compat.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def inspect_func_args(fn): if py3k: co = fn.__code__ else: co = fn.func_code nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) varargs = None if co.co_flags & CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & CO_VARKEYWORDS: varkw = co.co_varnames[nargs] if py3k: return args, varargs, varkw, fn.__defaults__ else: return args, varargs, varkw, fn.func_defaults
Example #10
Source File: langhelpers.py From planespotter with MIT License | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #11
Source File: langhelpers.py From android_universal with MIT License | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #12
Source File: langhelpers.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #13
Source File: compat.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)
Example #14
Source File: langhelpers.py From jarvis with GNU General Public License v2.0 | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #15
Source File: compat.py From sqlalchemy with MIT License | 5 votes |
def inspect_getfullargspec(func): """Fully vendored version of getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) kwonlyargs = list(names[nargs : nargs + nkwargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return FullArgSpec( args, varargs, varkw, func.__defaults__, kwonlyargs, func.__kwdefaults__ if py3k else None, func.__annotations__ if py3k else {}, )
Example #16
Source File: langhelpers.py From stdm with GNU General Public License v2.0 | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #17
Source File: langhelpers.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #18
Source File: compat.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)
Example #19
Source File: overloading.py From overloading.py with MIT License | 5 votes |
def get_signature(func): """ Gathers information about the call signature of `func`. """ code = func.__code__ # Names of regular parameters parameters = tuple(code.co_varnames[:code.co_argcount]) # Flags has_varargs = bool(code.co_flags & inspect.CO_VARARGS) has_varkw = bool(code.co_flags & inspect.CO_VARKEYWORDS) has_kwonly = bool(code.co_kwonlyargcount) # A mapping of parameter names to default values default_values = func.__defaults__ or () defaults = dict(zip(parameters[-len(default_values):], default_values)) # Type annotations for all parameters type_hints = typing.get_type_hints(func) if typing else func.__annotations__ types = tuple(normalize_type(type_hints.get(param, AnyType)) for param in parameters) # Type annotations for required parameters required = types[:-len(defaults)] if defaults else types # Complexity complexity = tuple(map(type_complexity, types)) if typing else None return Signature(parameters, types, complexity, defaults, required, has_varargs, has_varkw, has_kwonly)
Example #20
Source File: langhelpers.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #21
Source File: compat.py From mako with MIT License | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)
Example #22
Source File: compat.py From alembic with MIT License | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)
Example #23
Source File: compat.py From dogpile.cache with MIT License | 5 votes |
def inspect_getfullargspec(func): """Fully vendored version of getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) kwonlyargs = list(names[nargs : nargs + nkwargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return FullArgSpec( args, varargs, varkw, func.__defaults__, kwonlyargs, func.__kwdefaults__ if py3k else None, func.__annotations__ if py3k else {}, )
Example #24
Source File: compat.py From teleport with Apache License 2.0 | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)
Example #25
Source File: compat.py From teleport with Apache License 2.0 | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)
Example #26
Source File: langhelpers.py From jbox with MIT License | 5 votes |
def inspect_func_args(fn): co = fn.__code__ nargs = co.co_argcount names = co.co_varnames args = list(names[:nargs]) has_kw = bool(co.co_flags & CO_VARKEYWORDS) return args, has_kw
Example #27
Source File: compat.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def inspect_getargspec(func): """getargspec based on fully vendored getfullargspec from Python 3.3.""" if inspect.ismethod(func): func = func.__func__ if not inspect.isfunction(func): raise TypeError("{!r} is not a Python function".format(func)) co = func.__code__ if not inspect.iscode(co): raise TypeError("{!r} is not a code object".format(co)) nargs = co.co_argcount names = co.co_varnames nkwargs = co.co_kwonlyargcount if py3k else 0 args = list(names[:nargs]) nargs += nkwargs varargs = None if co.co_flags & inspect.CO_VARARGS: varargs = co.co_varnames[nargs] nargs = nargs + 1 varkw = None if co.co_flags & inspect.CO_VARKEYWORDS: varkw = co.co_varnames[nargs] return ArgSpec(args, varargs, varkw, func.__defaults__)