Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2412,9 +2412,9 @@ def _signature_from_callable(obj, *,
pass
else:
if text_sig:
# If 'obj' class has a __text_signature__ attribute:
# If 'base' class has a __text_signature__ attribute:
# return a signature based on it
return _signature_fromstr(sigcls, obj, text_sig)
return _signature_fromstr(sigcls, base, text_sig)

# No '__text_signature__' was found for the 'obj' class.
# Last option is to check if its '__init__' is
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4148,6 +4148,16 @@ def func(*args, **kwargs):
sig = inspect.signature(func)
self.assertEqual(str(sig), '(self, a, b=1, /, *args, c, d=2, **kwargs)')

def test_base_class_have_text_signature(self):
# see issue 43118
from io import BufferedReader
class MyBufferedReader(BufferedReader):
"""buffer reader class."""

self.assertTrue(hasattr(BufferedReader, '__text_signature__'))
sig = inspect.signature(MyBufferedReader)
self.assertIsNotNone(sig)
Comment thread
hongweipeng marked this conversation as resolved.
Outdated


class NTimesUnwrappable:
def __init__(self, n):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In :func:`inspect.signature`, if the 'base' class has ``__text_signature__``
attribute, use 'base' to help parse it. Patch by Weipeng Hong.
Comment thread
hongweipeng marked this conversation as resolved.
Outdated