doc strings of properties

Discussion in 'Python' started by Peter Dobcsanyi, Feb 27, 2004.

  1. Hi,

    I reworked a few methods of a class using properties but then realized
    that the online help in interactive sessions would not work as I
    expected. The reason is the way how doc strings of properties is treated.
    Here is an example to illuminate the problem:

    >>> class Foo(object):

    ... def __init__(self):
    ... self.a = 2
    ... self.b = 3
    ... def set(self, x, y):
    ... 'Set a and b.'
    ... self.a = x
    ... self.b = y
    ... def _axb(self):
    ... return self.a * self.b
    ... axb = property(_axb, doc='Return current product a*b.')
    ...
    >>>


    ()
    >>> print f.a, f.b, f.axb

    2 3 6
    >>>
    >>> print f.set.__doc__

    Set a and b.
    >>>
    >>> print f.axb.__doc__

    int(x[, base]) -> integer

    Convert a string or number to an integer, if possible. A floating point
    argument will be truncated towards zero (this does not include a string
    representation of a floating point number!) When converting a string,
    use
    the optional base. It is an error to supply a base when converting a
    non-string. If the argument is outside the integer range a long object
    will be returned instead.
    >>>
    >>> print Foo.axb.__doc__

    Return current product a*b.
    >>>


    I have a vague idea why this is happening, nevertheless find it a bit
    inconsistent compared to doc strings of standard methods. Things are not
    too helpful with help() either.

    >>> help(f.set)

    Help on method set:

    set(self, x, y) method of __main__.Foo instance
    Set a and b.

    >>> help(Foo.set)

    Help on method set:

    set(self, x, y) unbound __main__.Foo method
    Set a and b.

    >>> help(f.axb)

    Help on int:

    6

    >>> help(Foo.axb)

    Help on property:

    <property object>

    >>>


    Although, help on the class gives what one would expect:

    >>> help(Foo)

    Help on class Foo in module __main__:

    class Foo(__builtin__.object)
    | Methods defined here:
    |
    | __init__(self)
    |
    | set(self, x, y)
    | Set a and b.
    |
    |
    ----------------------------------------------------------------------
    | Properties defined here:
    |
    | axb
    | Return current product a*b.
    |
    | <get> = _axb(self)
    |
    ...

    Is there a way to work around this problem or I am missing something
    here.

    Thanks,
    Peter
     
    Peter Dobcsanyi, Feb 27, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Wallace
    Replies:
    0
    Views:
    476
    John Wallace
    Jul 22, 2003
  2. Matt
    Replies:
    3
    Views:
    510
    Tor Iver Wilhelmsen
    Sep 17, 2004
  3. Praveen Chhangani

    Converting a org.jdom DOC to org.w3c DOC

    Praveen Chhangani, Aug 5, 2003, in forum: XML
    Replies:
    2
    Views:
    971
    Johannes Koch
    Aug 7, 2003
  4. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    767
    Malcolm
    Jun 24, 2006
  5. News123
    Replies:
    0
    Views:
    296
    News123
    Feb 6, 2010
Loading...

Share This Page