This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author conqp
Recipients conqp
Date 2020-03-24.15:29:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently only plain strings can be used as docstrings, such as:

    class Foo:
        """Spamm eggs."""

For dynamic class generation, it would be useful to allow format strings as docstrings as well:

    doc = 'eggs'

    class Foo:
        """Spamm {}.""".format(doc)


    doc = 'eggs'

    class Foo:
        f"""Spamm {doc}."""

A current use case in which I realized that this feature was missing is:

    class OAuth2ClientMixin(Model, ClientMixin):   # pylint: disable=R0904
        """An OAuth 2.0 client mixin for peewee models."""


        def get_related_models(cls, model=Model):
            """Yields related models."""
            for mixin, backref in CLIENT_RELATED_MIXINS:
                yield cls._get_related_model(model, mixin, backref)

        def _get_related_model(cls, model, mixin, backref):
            """Returns an implementation of the related model."""
            class ClientRelatedModel(model, mixin):
                f"""Implementation of {mixin.__name__}."""
                client = ForeignKeyField(
                    cls, column_name='client', backref=backref,
                    on_delete='CASCADE', on_update='CASCADE')

            return ClientRelatedModel

It actually *is* possible to dynamically set the docstring via the __doc__ attribute:

    doc = 'eggs'

    class Foo:

    Foo.__doc__ = doc

Allowing format strings would imho be more obvious when reading the code as it is set, where a docstring is expected i.e. below the class / function definition.
Date User Action Args
2020-03-24 15:29:16conqpsetrecipients: + conqp
2020-03-24 15:29:16conqpsetmessageid: <>
2020-03-24 15:29:16conqplinkissue40054 messages
2020-03-24 15:29:15conqpcreate