Skip to content

Commit 169885c

Browse files
committed
Handle namedtuples' default __repr__ in prettiry_docstrings.
1 parent bbaab79 commit 169885c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

domdf_python_tools/doctools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,7 @@ def prettify_docstrings(obj: Type) -> Type:
370370
except AttributeError: # pragma: no cover
371371
pass
372372

373+
if issubclass(obj, tuple) and obj.__repr__.__doc__ == "Return a nicely formatted representation string":
374+
obj.__repr__.__doc__ = repr_docstring
375+
373376
return obj

tests/test_doctools.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# stdlib
1010
import math
11-
from typing import Iterable, get_type_hints
11+
from typing import Iterable, NamedTuple, get_type_hints
1212

1313
# 3rd party
1414
import pytest
@@ -550,3 +550,13 @@ class G(Dictable):
550550
pass
551551

552552
assert prettify_docstrings(G).__getitem__.__doc__ != "Return ``self[key]``."
553+
554+
555+
def test_prettify_namedtuple():
556+
557+
@prettify_docstrings
558+
class T(NamedTuple):
559+
a: str
560+
b: float
561+
562+
assert T.__repr__.__doc__ == "Return a string representation of the :class:`~tests.test_doctools.T`."

0 commit comments

Comments
 (0)