[IPython-dev] let ipython return parent's class method docstring automatically
Ondrej Certik
ondrej@certik...
Wed Jul 23 15:11:04 CDT 2008
Hi,
we are with Mateusz Paprocki at my place doing some hacking and we'd
like to know what is the best way to handle the following situation in
sympy:
In [1]: e = x*y
In [2]: e.nseries?
Type: instancemethod
Base Class: <type 'instancemethod'>
String Form: <bound method Mul.nseries of x*y>
Namespace: Interactive
File: /home/ondra/sympy/sympy/core/mul.py
Definition: e.nseries(self, x, x0, n)
Docstring:
<no docstring>
So the Mul.nseries() is missing a docstring, but:
In [4]: print e.__class__.__base__.nseries.__doc__
Calculates a generalized series expansion.
The difference between oseries and nseries is that nseries calculates
"n" terms in the innermost expressions and then builds up the final
series just by "cross-mutliplying" everything out.
Advantage -- it's fast, because we don't have to determine how many
terms we need to calculate in advance.
Disadvantage -- you may endup with less terms than you may have
expected, but the O(x**n) term appended will always be correct, so the
result is correct, but maybe shorter.
The partent class, in this case Basic, has a nice docstring. The thing
is, that the Basic class has the docstring, but the child classes
don't (obviously, because it'd be the same).
What is the best way to handle this?
We can see two possibilities:
1) patch ipython to return parent's (or parent's parent's) docstring.
I checked that and the patch would be just a few lines of code in
OInspect.py
2) have just Basic.nseries() method and use _eval_nseries() in all
subclasses. That way, if the user types e.nseries(), the
Basic.nseries() with a nice docstring will be invoked.
So I'd like to ask the ipython guys if 1) is the way to go, or rather
2)? Or is there also some other way to fix this.
Ondrej & Mateusz
More information about the IPython-dev
mailing list