mirror of https://github.com/python/cpython.git
bpo-43118: Fix bug in inspect.signature around 'base.__text_signature__' (GH-30285)
This commit is contained in:
parent
00b2b578bd
commit
881a763cfe
|
@ -2511,9 +2511,9 @@ def _signature_from_callable(obj, *,
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if text_sig:
|
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 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.
|
# No '__text_signature__' was found for the 'obj' class.
|
||||||
# Last option is to check if its '__init__' is
|
# Last option is to check if its '__init__' is
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Tests class have ``__text_signature__``
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DEFAULT_BUFFER_SIZE = 8192
|
||||||
|
|
||||||
|
class BufferedReader(object):
|
||||||
|
"""BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n
|
||||||
|
Create a new buffered reader using the given readable raw IO object.
|
||||||
|
"""
|
||||||
|
pass
|
|
@ -4151,6 +4151,17 @@ def func(*args, **kwargs):
|
||||||
sig = inspect.signature(func)
|
sig = inspect.signature(func)
|
||||||
self.assertEqual(str(sig), '(self, a, b=1, /, *args, c, d=2, **kwargs)')
|
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 test.ann_module7 import BufferedReader
|
||||||
|
class MyBufferedReader(BufferedReader):
|
||||||
|
"""buffer reader class."""
|
||||||
|
|
||||||
|
text_signature = BufferedReader.__text_signature__
|
||||||
|
self.assertEqual(text_signature, '(raw, buffer_size=DEFAULT_BUFFER_SIZE)')
|
||||||
|
sig = inspect.signature(MyBufferedReader)
|
||||||
|
self.assertEqual(str(sig), '(raw, buffer_size=8192)')
|
||||||
|
|
||||||
|
|
||||||
class NTimesUnwrappable:
|
class NTimesUnwrappable:
|
||||||
def __init__(self, n):
|
def __init__(self, n):
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix a bug in :func:`inspect.signature` that was causing it to fail on some
|
||||||
|
subclasses of classes with a ``__text_signature__`` referencing module
|
||||||
|
globals. Patch by Weipeng Hong.
|
Loading…
Reference in New Issue