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

  • SEARCH
  • Home
  • 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 600961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:39:47+00:00 2026-05-13T16:39:47+00:00

I prefer to document each parameter (as needed) on the same line where I

  • 0

I prefer to document each parameter (as needed) on the same line where I declare the parameter in order to apply D.R.Y.

If I have code like this:

def foo(
        flab_nickers, # a series of under garments to process
        has_polka_dots=False,
        needs_pressing=False  # Whether the list of garments should all be pressed
   ):
    ...

How can I avoid repeating the parameters in the doc string and retain the parameter explanations?

I want to avoid:

def foo(
        flab_nickers, # a series of under garments to process
        has_polka_dots=False,
        needs_pressing=False  # Whether the list of garments should all be pressed
    ):
    '''Foo does whatever.

    * flab_nickers - a series of under garments to process
    * needs_pressing - Whether the list of garments should all be pressed.
      [Default False.]

Is this possible in python 2.6 or python 3 with some sort of decorator manipulation? Is there some other way?

  • 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-05-13T16:39:47+00:00Added an answer on May 13, 2026 at 4:39 pm

    I would do this.

    Starting with this code.

    def foo(
            flab_nickers, # a series of under garments to process
            has_polka_dots=False,
            needs_pressing=False  # Whether the list of garments should all be pressed
       ):
        ...
    

    I would write a parser that grabs the function parameter definitions and builds the following:

    def foo(
            flab_nickers, 
            has_polka_dots=False,
            needs_pressing=False,
       ):
       """foo
    
       :param flab_nickers: a series of under garments to process
       :type flab_nickers: list or tuple
       :param has_polka_dots: default False
       :type has_polka_dots: bool
       :param needs_pressing: default False, Whether the list of garments should all be pressed
       :type needs_pressing: bool
       """
        ...
    

    That’s some pretty straight-forward regex processing of the various arguments string patterns to fill in the documentation template.

    A lot of good Python IDEs (for example PyCharm) understand the default Sphinx param notation and even flag vars/methods in the scope that IDE thinks does not conform to the declared type.

    Note the extra comma in the code; that’s just to make things consistent. It does no harm, and it might simplify things in the future.

    You can also try and use the Python compiler to get a parse tree, revise it and emit the update code. I’ve done this for other languages (not Python), so I know a little bit about it, but don’t know how well supported it is in Python.

    Also, this is a one-time transformation.

    The original in-line comments in the function definition don’t really follow DRY because it’s a comment, in an informal language, and unusable by any but the most sophisticated tools.

    The Sphinx comments are closer to DRY because they’re in the RST markup language, making them much easier to process using ordinary text-parsing tools in docutils.

    It’s only DRY if tools can make use of it.

    Useful links:
    https://pythonhosted.org/an_example_pypi_project/sphinx.html#function-definitions
    http://sphinx-doc.org/domains.html#id1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Perhaps when the 2nd site recompiles some class or other… May 14, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer Whatever the reason is, it really doesn't matter as long… May 14, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer You might want to try: module Foo module BarWoo def… May 14, 2026 at 8:15 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.