Documenting properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lasse Vågsæther Karlsen

    #1

    Documenting properties

    I notice that if I use this syntax:

    def classname:
    ...
    ##
    # closes the database connection and releases the resources.
    def close(self):
    ....

    ##
    # Returns a list of fields
    fields = property(....)

    then doing:

    help (classname)

    then the text is listed for the property and the method, whereas if I do
    this:

    classname.close .__doc__

    then nothing is listed, and to get that I have to use the """.."""
    syntax to document:

    def close(self):
    """closes the datab..."""
    ....

    then classname.close .__doc__ shows the text.

    So, my question is, is there a way to get __doc__ support for
    properties, in effect, use the """xxx""" syntax for documenting properties.

    Is the preferred way to use """xxx""" or # to document ?
    Whatever is preferred, what's the upside/downsides of the two beyond
    what I just explained?

    --
    Lasse Vågsæther Karlsen

    mailto:lasse@vk arlsen.no
    PGP KeyID: 0x2A42A1C2
  • Paul McNett

    #2
    Re: Documenting properties

    Lasse Vågsæther Karlsen wrote:[color=blue]
    > So, my question is, is there a way to get __doc__ support for
    > properties, in effect, use the """xxx""" syntax for documenting properties.[/color]

    Yes, the property() function accepts a doc argument, as in:

    property(fget, fset, fdel, doc)

    ex:
    MyProp = property(_get, _set, None, "This will show up in __doc__")

    [color=blue]
    > Is the preferred way to use """xxx""" or # to document ?[/color]

    # is for source code commenting (audience is the person reading your
    code). """x""" is for documenting your API (audience is the person using
    your code). They are quite different.

    [color=blue]
    > Whatever is preferred, what's the upside/downsides of the two beyond
    > what I just explained?[/color]

    Nothing really, but something handy to keep in mind is that the string
    literal ("""x""") can be used to block out huge sections of code during
    testing, where you'd have to put a # in front of every line otherwise.

    --
    Paul McNett




    Comment

    • Gerrit Holl

      #3
      Re: Documenting properties

      Paul McNett wrote:[color=blue][color=green]
      > > Whatever is preferred, what's the upside/downsides of the two beyond
      > > what I just explained?[/color]
      >
      > Nothing really, but something handy to keep in mind is that the string
      > literal ("""x""") can be used to block out huge sections of code during
      > testing, where you'd have to put a # in front of every line otherwise.[/color]

      Except, of course, code that contains string literals with triple
      quotes. And with a good editor, it's not too difficult to insert a # in
      front of hundreds of lines (:%s/^/#/g).

      Gerrit.

      --
      Temperature in Luleå, Norrbotten, Sweden:
      | Current temperature 05-09-27 20:19:54 9.8 degrees Celsius ( 49.7F) |
      --
      Det finns inte dåligt väder, bara dåliga kläder.

      Comment

      Working...