mirror of https://github.com/python/cpython.git
gh-103449: Fix a bug in dataclass docstring generation (#103454)
This commit is contained in:
parent
d83faf7f1b
commit
b57f55c23e
|
@ -1128,8 +1128,13 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
|
||||||
|
|
||||||
if not getattr(cls, '__doc__'):
|
if not getattr(cls, '__doc__'):
|
||||||
# Create a class doc-string.
|
# Create a class doc-string.
|
||||||
cls.__doc__ = (cls.__name__ +
|
try:
|
||||||
str(inspect.signature(cls)).replace(' -> None', ''))
|
# In some cases fetching a signature is not possible.
|
||||||
|
# But, we surely should not fail in this case.
|
||||||
|
text_sig = str(inspect.signature(cls)).replace(' -> None', '')
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
text_sig = ''
|
||||||
|
cls.__doc__ = (cls.__name__ + text_sig)
|
||||||
|
|
||||||
if match_args:
|
if match_args:
|
||||||
# I could probably compute this once
|
# I could probably compute this once
|
||||||
|
|
|
@ -2297,6 +2297,19 @@ class C:
|
||||||
|
|
||||||
self.assertDocStrEqual(C.__doc__, "C(x:collections.deque=<factory>)")
|
self.assertDocStrEqual(C.__doc__, "C(x:collections.deque=<factory>)")
|
||||||
|
|
||||||
|
def test_docstring_with_no_signature(self):
|
||||||
|
# See https://github.com/python/cpython/issues/103449
|
||||||
|
class Meta(type):
|
||||||
|
__call__ = dict
|
||||||
|
class Base(metaclass=Meta):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class C(Base):
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertDocStrEqual(C.__doc__, "C")
|
||||||
|
|
||||||
|
|
||||||
class TestInit(unittest.TestCase):
|
class TestInit(unittest.TestCase):
|
||||||
def test_base_has_init(self):
|
def test_base_has_init(self):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix a bug in doc string generation in :func:`dataclasses.dataclass`.
|
Loading…
Reference in New Issue