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 8615699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:26:37+00:00 2026-06-12T05:26:37+00:00

On the one hand, we are encouraged to just create fields, and not encrust

  • 0

On the one hand, we are encouraged to just create fields, and not encrust our python classes with extra accessor functions modelled on other languages.

On the other hand, the PEP for ‘attribute docstrings’ was rejected.

On the third hand, epydoc and sphinx support them. At the risk of a nonconstructive question, is there a single, clear, common practice for documenting variables in classes?

  • 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-12T05:26:39+00:00Added an answer on June 12, 2026 at 5:26 am

    I rephrase my comment as an answer since I was asked to do so.

    Generally instance (public) attributes are self-explanatory and their usage by the user does not require documentation. The name of the attribute and the context is enough to make clear what the attribute is and you can add a bit of documentation about how to handle it in the class’s documentation.

    You may end up in some circumstances in which you would like to provide the user the access of an attribute but the attribute is not self-explanatory enough and/or its handling requires attention(because if not handled correctly it could “blow things up”).

    For example you may want to let the user know that an attribute should have a specific “interface” in order to allow it to be used. Or you have to explain a condition that must be met by the attribute.

    In this cases putting the documentation together with the class’s doc is not a good idea, because the class’s documentation gets longer and longer and it explain a lot of really specific knowledge.

    The simple and, I think, more elegant solution is to use properties.
    Properties let you add a docstring to the attribute and give you a way to actually control the access over it, thus allowing to make the class more robust.

    If you have to deal with a lot of attributes then it may be troublesome to write tens of properties, but you can still add them dynamically, for example using a decorator.
    This works well especially if you just want to add a docstring, using always the same kind of getter/setter.

    For example you could write:

    def set_properties(names_to_docs):
        def decorator(cls):
            for name, doc in names_to_docs.items():
                prop = property((lambda self: getattr(self, '_{}'.format(name))),
                                (lambda self, val: setattr(self, '_{}'.format(name), val),
                                doc=doc)
                setattr(cls, name, prop)
            return cls
        return decorator
    

    And use it like this:

    >>> @set_properties({'a': 'This is a', 'b': 'This is b'})
    >>> class Test:
    ...     def __init__(self):
    ...         self._a = 1
    ...         self._b = 2
    ... 
    >>> print(Test.a.__doc__)
    This is a
    >>> Test().a
    1
    

    In a comment Lukas Graf pointed out that you may use Zope.interface to create a class which simply describes the concrete class, which gives you a chance to add docstrings to attributes. This would probably be an other option.
    I’m not experienced in using Zope.interface so I can’t tell exactly what can you do and how, and how it interacts, eventually, with auto-documentation programs.

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

Sidebar

Related Questions

I have a Coda slider on one webpage (hand-crafted, not using the plugin, but
On the one hand, if his friends haven't signed in we may not know
On one hand, I'm just curious. On the other, I have to count somehow
For our database development we have on one hand a full schema DDL script,
our project structure has been split. On the one hand there is the /plugins
On the one hand, I read or hear that function calls are expensive and
I'm writing a 7 card poker hand evaluator as one of my pet projects.
I am calculating one parameter(X) this way: <?php $link=mysql_connect(localhost,root,); mysql_select_db(hand); $result = mysql_query(select *
one question about PHP Development. I am building up some Form Fields for Calculations.
On one hand, I know that the advisable usage of Properties is to have

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.