Skip to content

Is it possible to pre-process docstrings? #190

Closed Answered by pawamoy
JuroOravec asked this question in Q&A
Discussion options

You must be logged in to vote

Nice use-case @JuroOravec 🙂

The best way to pre-process docstrings is to write a Griffe extension. Quick example:

import griffe


def _preprocess(docstring: griffe.Docstring) -> None:
    docstring.value = re.sub(..., ..., docstring.value)  # your preprocessing logic
    # if you have a look at Griffe's API, you might be tempted to use docstring.parsed instead,
    # but I don't recommend mutating the parsed version
    # as there are chances it stops being cached in the future


class ComponentSyntaxes(griffe.Extension):
    def on_class_instance(self, cls: griffe.Class, **kwargs) -> None:
        if cls.docstring:
            _preprocess(cls.docstring)

Let me know if that helps! Happy t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JuroOravec
Comment options

@pawamoy
Comment options

@JuroOravec
Comment options

Answer selected by JuroOravec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy