diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/idlelib/idle_test/test_calltips.py | 4 | ||||
-rw-r--r-- | Lib/inspect.py | 21 | ||||
-rw-r--r-- | Lib/test/test_capi.py | 2 | ||||
-rw-r--r-- | Lib/test/test_generators.py | 4 | ||||
-rw-r--r-- | Lib/test/test_genexps.py | 4 |
5 files changed, 16 insertions, 19 deletions
diff --git a/Lib/idlelib/idle_test/test_calltips.py b/Lib/idlelib/idle_test/test_calltips.py index ab69bd018b..4ee15aef76 100644 --- a/Lib/idlelib/idle_test/test_calltips.py +++ b/Lib/idlelib/idle_test/test_calltips.py @@ -54,9 +54,9 @@ class Get_signatureTest(unittest.TestCase): gtest(List, List.__doc__) gtest(list.__new__, - 'T.__new__(S, ...) -> a new object with type S, a subtype of T') + 'Create and return a new object. See help(type) for accurate signature.') gtest(list.__init__, - 'x.__init__(...) initializes x; see help(type(x)) for signature') + 'Initialize self. See help(type(self)) for accurate signature.') append_doc = "L.append(object) -> None -- append object to end" gtest(list.append, append_doc) gtest([].append, append_doc) 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) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 444feb6314..0ec3ca3eeb 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -125,7 +125,7 @@ class CAPITest(unittest.TestCase): self.assertEqual(_testcapi.docstring_no_signature.__text_signature__, None) self.assertEqual(_testcapi.docstring_with_invalid_signature.__doc__, - "docstring_with_invalid_signature (module, boo)\n" + "sig= (module, boo)\n" "\n" "This docstring has an invalid signature." ) diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 5b7424bcf8..91afe47799 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -436,8 +436,8 @@ From the Iterators list, about the types of these things. >>> [s for s in dir(i) if not s.startswith('_')] ['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw'] >>> from test.support import HAVE_DOCSTRINGS ->>> print(i.__next__.__doc__ if HAVE_DOCSTRINGS else 'Implements next(self).') -Implements next(self). +>>> print(i.__next__.__doc__ if HAVE_DOCSTRINGS else 'Implement next(self).') +Implement next(self). >>> iter(i) is i True >>> import types diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py index 74957cb8f4..fb531d6d47 100644 --- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -222,8 +222,8 @@ Check that generator attributes are present True >>> from test.support import HAVE_DOCSTRINGS - >>> print(g.__next__.__doc__ if HAVE_DOCSTRINGS else 'Implements next(self).') - Implements next(self). + >>> print(g.__next__.__doc__ if HAVE_DOCSTRINGS else 'Implement next(self).') + Implement next(self). >>> import types >>> isinstance(g, types.GeneratorType) True |