diff options
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 0be0419..ff25be7 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -161,7 +161,6 @@ def isframe(object): f_lasti index of last attempted instruction in bytecode f_lineno current line number in Python source code f_locals local namespace seen by this frame - f_restricted 0 or 1 if frame is in restricted execution mode f_trace tracing function for this frame, or None""" return isinstance(object, types.FrameType) @@ -674,7 +673,7 @@ def getargs(co): """Get information about the arguments accepted by a code object. Three things are returned: (args, varargs, varkw), where - 'args' is the list of argument names, possibly containing nested + 'args' is the list of argument names, possibly containing nested lists. Keyword-only arguments are appended. 'varargs' and 'varkw' are the names of the * and ** arguments or None.""" args, varargs, kwonlyargs, varkw = _getfullargs(co) @@ -751,7 +750,7 @@ def getargspec(func): 'args' will include keyword-only argument names. 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'defaults' is an n-tuple of the default values of the last n arguments. - + Use the getfullargspec() API for Python-3000 code, as annotations and keyword arguments are supported. getargspec() will raise ValueError if the func has either annotations or keyword arguments. @@ -767,7 +766,7 @@ def getargspec(func): def getfullargspec(func): """Get the names and default values of a function's arguments. - A tuple of seven things is returned: (args, varargs, kwonlyargs, + A tuple of seven things is returned: (args, varargs, kwonlyargs, kwonlydefaults, varkw, defaults, annotations). 'args' is a list of the argument names (it may contain nested lists). 'varargs' and 'varkw' are the names of the * and ** arguments or None. @@ -775,7 +774,7 @@ def getfullargspec(func): 'kwonlyargs' is a list of keyword-only argument names. 'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults. 'annotations' is a dictionary mapping argument names to annotations. - + The first four items in the tuple correspond to getargspec(). """ @@ -784,7 +783,7 @@ def getfullargspec(func): if not isfunction(func): raise TypeError('arg is not a Python function') args, varargs, kwonlyargs, varkw = _getfullargs(func.__code__) - return (args, varargs, varkw, func.__defaults__, + return (args, varargs, varkw, func.__defaults__, kwonlyargs, func.__kwdefaults__, func.__annotations__) def getargvalues(frame): @@ -816,12 +815,12 @@ def formatannotation(annotation, base_module=None): return annotation.__name__ return annotation.__module__+'.'+annotation.__name__ return repr(annotation) - + def formatannotationrelativeto(object): - module = getattr(object, '__module__', None) - def _formatannotation(annotation): - return formatannotation(annotation, module) - return _formatannotation + module = getattr(object, '__module__', None) + def _formatannotation(annotation): + return formatannotation(annotation, module) + return _formatannotation def formatargspec(args, varargs=None, varkw=None, defaults=None, kwonlyargs=(), kwonlydefaults={}, annotations={}, @@ -832,7 +831,7 @@ def formatargspec(args, varargs=None, varkw=None, defaults=None, formatreturns=lambda text: ' -> ' + text, formatannotation=formatannotation, join=joinseq): - """Format an argument spec from the values returned by getargspec + """Format an argument spec from the values returned by getargspec or getfullargspec. The first seven arguments are (args, varargs, varkw, defaults, |