sharing data across Examples docstrings

Chris Angelico rosuav at gmail.com
Tue Jan 11 17:17:03 EST 2022


On Wed, Jan 12, 2022 at 9:11 AM Sebastian Luque <spluque at gmail.com> wrote:
>
> Hello,
>
> I am searching for a mechanism for sharing data across Examples sections
> in docstrings within a class.  For instance:

This seems like trying to cram too much information into the
docstring, but oh well... do what you will.

I'd recommend a decorator. The easiest way would probably be to have a
placeholder of some sort in the actual docstring, and in the
decorator, you replace __doc__ with the modified form.

To do what you're asking for, your decorator would either need to go
through every method in the class and mutate its docstring (in which
case you'd decorate the class), or mutate the docstring of exactly one
function (in which case you'd decorate that method).

ChrisA


More information about the Python-list mailing list