doc strings of properties

P

Peter Dobcsanyi

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:
... 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.')
...
() 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.
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 on method set:

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

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

6
Help on property:


Although, help on the class gives what one would expect:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top