summaryrefslogtreecommitdiff
path: root/Lib/inspect.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py38
1 files changed, 16 insertions, 22 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index e830eb64ca..45d2110106 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -16,7 +16,7 @@ Here are some of the useful functions provided by this module:
getmodule() - determine the module that an object came from
getclasstree() - arrange classes so as to represent their hierarchy
- getargspec(), getargvalues(), getcallargs() - get info about function arguments
+ getargvalues(), getcallargs() - get info about function arguments
getfullargspec() - same, with support for Python 3 features
formatargspec(), formatargvalues() - format an argument spec
getouterframes(), getinnerframes() - get info about frames
@@ -624,23 +624,6 @@ def getfile(object):
raise TypeError('{!r} is not a module, class, method, '
'function, traceback, frame, or code object'.format(object))
-ModuleInfo = namedtuple('ModuleInfo', 'name suffix mode module_type')
-
-def getmoduleinfo(path):
- """Get the module name, suffix, mode, and module type for a given file."""
- warnings.warn('inspect.getmoduleinfo() is deprecated', DeprecationWarning,
- 2)
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', PendingDeprecationWarning)
- import imp
- filename = os.path.basename(path)
- suffixes = [(-len(suffix), suffix, mode, mtype)
- for suffix, mode, mtype in imp.get_suffixes()]
- suffixes.sort() # try longest suffixes first, in case they overlap
- for neglen, suffix, mode, mtype in suffixes:
- if filename[neglen:] == suffix:
- return ModuleInfo(filename[:neglen], suffix, mode, mtype)
-
def getmodulename(path):
"""Return the module name for a given file, or None."""
fname = os.path.basename(path)
@@ -1061,8 +1044,6 @@ def getfullargspec(func):
'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().
-
This function is deprecated, use inspect.signature() instead.
"""
@@ -1173,8 +1154,7 @@ def formatargspec(args, varargs=None, varkw=None, defaults=None,
formatvalue=lambda value: '=' + repr(value),
formatreturns=lambda text: ' -> ' + text,
formatannotation=formatannotation):
- """Format an argument spec from the values returned by getargspec
- or getfullargspec.
+ """Format an argument spec from the values returned by getfullargspec.
The first seven arguments are (args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations). The other five arguments
@@ -2416,6 +2396,20 @@ class Parameter:
if not isinstance(name, str):
raise TypeError("name must be a str, not a {!r}".format(name))
+ if name[0] == '.' and name[1:].isdigit():
+ # These are implicit arguments generated by comprehensions. In
+ # order to provide a friendlier interface to users, we recast
+ # their name as "implicitN" and treat them as positional-only.
+ # See issue 19611.
+ if kind != _POSITIONAL_OR_KEYWORD:
+ raise ValueError(
+ 'implicit arguments must be passed in as {}'.format(
+ _POSITIONAL_OR_KEYWORD
+ )
+ )
+ self._kind = _POSITIONAL_ONLY
+ name = 'implicit{}'.format(name[1:])
+
if not name.isidentifier():
raise ValueError('{!r} is not a valid parameter name'.format(name))