From 697da6e4bc58b1cf967154a3ae8092833b0731ff Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:08:04 +0000 Subject: [PATCH] Remove possible RecursionError in ``ASTBaseBase.__repr__()`` --- sphinx/util/cfamily.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sphinx/util/cfamily.py b/sphinx/util/cfamily.py index 127b1b247b5..05b5b89222f 100644 --- a/sphinx/util/cfamily.py +++ b/sphinx/util/cfamily.py @@ -115,7 +115,7 @@ def clone(self) -> Any: return deepcopy(self) def _stringify(self, transform: StringifyTransform) -> str: - raise NotImplementedError(repr(self)) + raise NotImplementedError def __str__(self) -> str: return self._stringify(str) @@ -124,7 +124,9 @@ def get_display_string(self) -> str: return self._stringify(lambda ast: ast.get_display_string()) def __repr__(self) -> str: - return f'<{self.__class__.__name__}: {self._stringify(repr)}>' + if repr_string := self._stringify(repr): + return f'<{self.__class__.__name__}: {repr_string}>' + return f'<{self.__class__.__name__}>' ################################################################################