Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:13:57+00:00 2026-06-08T20:13:57+00:00

I am documenting code in Sphinx that resembles this: class ParentClass(object): def __init__(self): pass

  • 0

I am documenting code in Sphinx that resembles this:

class ParentClass(object):
    
    def __init__(self):
        pass

    def generic_fun(self):
        """Call this function using /run/ParentClass/generic_fun()"""
        do_stuff()

class ChildClass(ParentClass):
    
    def specific_fun(self):
        """Call this function using /run/ChildClass/specific_fun()"""
        do_other_stuff()

I added the :inherited-members to the ChildClass documentation, so I have statements in there like "Call this function using /run/ParentClass/generic_fun()".

Is there a way I can put something in the docstrings like <class_name> that Sphinx will replace with the actual class that it’s documenting?

I would like to have the code look like:

class ParentClass(object):
    
    def __init__(self):
        pass

    def generic_fun(self):
        """Call this function using /run/<class_name>/generic_fun()"""
        do_stuff()

So in the ChildClass section, the Sphinx documentation would read "(…) using /run/ChildClass/generic_fun()(…)" and the ParentClass section would read "(…) using /run/ParentClass/generic_fun()(…)"?

Ideally I’d like to have the documentation on the same page, so the replacement string would be different for different sections.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:13:58+00:00Added an answer on June 8, 2026 at 8:13 pm

    I figured out a way to do this while looking at something else.

    There are functions autodoc will call before printing the message. I added this code to my conf.py file:

    def get_class_name(full_module_name):
        """
        Pull out the class name from the full_module_name
        """
        #split the full_module_name by "."'s
        return full_module_name.split('.')[-1]
    
    def process_docstring(app, what, name, obj, options, lines):
        classname = get_class_name(name)
    
        # loop through each line in the docstring and replace |class| with
        # the classname
        for i in xrange(len(lines)):
            lines[i] = lines[i].replace('|class|', classname)
    
    def setup(app):
        app.connect('autodoc-process-docstring', process_docstring)
    

    I want to use the | token, but they are reserved for global substitutions. I got around that by putting the following line my rst file (so the code substitutes |class| for |class|):

    .. |class| replace:: `|class|`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a colleague who insists that his code doesn't need comments, it's "self
Suppose, that as part of documenting your code (Javadoc) you want to indicate that
I have a small library of code that I am documenting with YARD .
I'm documenting code C with doxygen but this function can´t /** * @fn void
Just documenting this as a question an answer so that somebody else doesn't have
All the files in the code base I am documenting will always use the
My code : <div class=allegati-item> <div class=allegati-titolo>Download</div> <a class=allegati-link href=/documenti/DocumentoTest.pdf>Link1</a> <a class=allegati-link href=/documenti/DocumentoTest.pdf>Link2</a> </div>
I've been documenting a software package using Sphinx and reStructuredText . Within my documents,
I'm documenting code in Eclipse and have been using the /** followed by Enter
I am documenting some code which uses meta-programming heavily, for example: template<rysq::type A, rysq::type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.