From 300d6c14ac39e504a08c8d5df25d5e4544eed98a Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Tue, 27 Aug 2024 14:59:19 -0500 Subject: [PATCH] fixes for getting docstrings of Procedures --- asteval/astutils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/asteval/astutils.py b/asteval/astutils.py index 3b458ad..c8b5df0 100644 --- a/asteval/astutils.py +++ b/asteval/astutils.py @@ -520,7 +520,13 @@ def __setattr__(self, attr, val): self.__dict__[attr] = val def __dir__(self): - return ['name'] + return ['_getdoc', 'argnames', 'kwargs', 'name', 'vararg', 'varkws'] + + def _getdoc(self): + doc = self.__doc__ + if isinstance(doc, ast.Constant): + doc = doc.s + return doc def __repr__(self): """TODO: docstring in magic method.""" @@ -538,8 +544,9 @@ def __repr__(self): if self.varkws is not None: sig = f"%sig, **{self.varkws}" sig = f"" - if self.__doc__ is not None: - sig = f"{sig}\n {self.__doc__}" + doc = self._getdoc() + if doc is not None: + sig = f"{sig}\n {doc}" return sig def __call__(self, *args, **kwargs):