diff options
author | Larry Hastings <larry@hastings.org> | 2014-01-28 13:00:08 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2014-01-28 13:00:08 (GMT) |
commit | 581ee3618c756132359d98b6fc149ec7e7ca9ef9 (patch) | |
tree | fa211357051306722af3b064f5b095992105524c /Lib/inspect.py | |
parent | eecbbad89b60c20641fa8dd1c12f52b3648408ea (diff) | |
download | cpython-581ee3618c756132359d98b6fc149ec7e7ca9ef9.zip cpython-581ee3618c756132359d98b6fc149ec7e7ca9ef9.tar.gz cpython-581ee3618c756132359d98b6fc149ec7e7ca9ef9.tar.bz2 |
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.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 2211b8d..5f37a2a 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) |