summaryrefslogtreecommitdiff
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2014-01-28 05:00:08 -0800
committerLarry Hastings <larry@hastings.org>2014-01-28 05:00:08 -0800
commit581ee3618c756132359d98b6fc149ec7e7ca9ef9 (patch)
treefa211357051306722af3b064f5b095992105524c /Lib/inspect.py
parenteecbbad89b60c20641fa8dd1c12f52b3648408ea (diff)
downloadcpython-git-581ee3618c756132359d98b6fc149ec7e7ca9ef9.tar.gz
Issue #20326: Argument Clinic now uses a simple, unique signature to
annotate text signatures in docstrings, resulting in fewer false positives. "self" parameters are also explicitly marked, allowing inspect.Signature() to authoritatively detect (and skip) said parameters. Issue #20326: Argument Clinic now generates separate checksums for the input and output sections of the block, allowing external tools to verify that the input has not changed (and thus the output is not out-of-date).
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 2211b8d4e0..5f37a2a6dd 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1998,6 +1998,10 @@ class Signature:
else:
kind = Parameter.POSITIONAL_OR_KEYWORD
+ first_parameter_is_self = s.startswith("($")
+ if first_parameter_is_self:
+ s = '(' + s[2:]
+
s = "def foo" + s + ": pass"
try:
@@ -2102,18 +2106,11 @@ class Signature:
kind = Parameter.VAR_KEYWORD
p(f.args.kwarg, empty)
- if parameters and (hasattr(func, '__self__') or
- isinstance(func, _WrapperDescriptor,) or
- ismethoddescriptor(func)
- ):
- name = parameters[0].name
- if name not in ('self', 'module', 'type'):
- pass
- elif getattr(func, '__self__', None):
- # strip off self (it's already been bound)
- p = parameters.pop(0)
- if not p.name in ('self', 'module', 'type'):
- raise ValueError('Unexpected name ' + repr(p.name) + ', expected self/module/cls/type')
+ if first_parameter_is_self:
+ assert parameters
+ if getattr(func, '__self__', None):
+ # strip off self, it's already been bound
+ parameters.pop(0)
else:
# for builtins, self parameter is always positional-only!
p = parameters[0].replace(kind=Parameter.POSITIONAL_ONLY)