%pdoc np.ma.compress shows docstring twice #89

Closed
ipython opened this Issue May 10, 2010 · 4 comments

Comments

Projects
None yet
3 participants
@ghost
Collaborator

ghost commented May 10, 2010

Original Launchpad bug 521612: https://bugs.launchpad.net/ipython/+bug/521612
Reported by: fdo.perez (Fernando Perez).

No idea why, but querying np.ma.compress with ? or %pdoc double-prints the docstring, with the second copy indented.

See this numpy thread for some context:

http://mail.scipy.org/pipermail/numpy-discussion/2010-February/048634.html

That object has a runtime-generated docstring, but I checked and its doc is OK (no duplication there). So the bug is definitely ours.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Mar 23, 2011

Member

The object implements a .getdoc() method. IPython.core.oinspect.getdoc() reckons that, if an object has a .getdoc() method as well as a normal docstring, the result of calling it should be treated as extra information, and concatenated together.

Are there actually any cases where .getdoc() adds info to the normal docstring, or can we simplify it to only check .getdoc() if it doesn't get a normal docstring. Otherwise, one possible way round this is to use textwrap.dedent, then compare the two, and only show both if they differ. Or perhaps, if they're both over a certain length, only show one.

Member

takluyver commented Mar 23, 2011

The object implements a .getdoc() method. IPython.core.oinspect.getdoc() reckons that, if an object has a .getdoc() method as well as a normal docstring, the result of calling it should be treated as extra information, and concatenated together.

Are there actually any cases where .getdoc() adds info to the normal docstring, or can we simplify it to only check .getdoc() if it doesn't get a normal docstring. Otherwise, one possible way round this is to use textwrap.dedent, then compare the two, and only show both if they differ. Or perhaps, if they're both over a certain length, only show one.

@ghost ghost assigned fperez Apr 10, 2011

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Nov 30, 2011

Member

@takluyver, agreed: we should probably change our behavior and only call getdoc if we didn't get a docstring. Should be an easy fix.

Member

fperez commented Nov 30, 2011

@takluyver, agreed: we should probably change our behavior and only call getdoc if we didn't get a docstring. Should be an easy fix.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Nov 30, 2011

Member

I wonder if we should possibly prefer .getdoc() over a normal docstring, on the basis that it might offer more customised information? I don't know how many or what objects implement getdoc.

Member

takluyver commented Nov 30, 2011

I wonder if we should possibly prefer .getdoc() over a normal docstring, on the basis that it might offer more customised information? I don't know how many or what objects implement getdoc.

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Nov 30, 2011

Member

That's a good point. I think it's fairly rare, so anyone implementing it must have had a good reason to do it, and we might as well honor it. Since using both is definitely a bug, I agree we could go with letting getdoc take precedence, unless what it returns is not a string, case in which we fall back to __doc__.

Member

fperez commented Nov 30, 2011

That's a good point. I think it's fairly rare, so anyone implementing it must have had a good reason to do it, and we might as well honor it. Since using both is definitely a bug, I agree we could go with letting getdoc take precedence, unless what it returns is not a string, case in which we fall back to __doc__.

takluyver added a commit to takluyver/ipython that referenced this issue Nov 30, 2011

@fperez fperez closed this in 8a4e8d9 Dec 6, 2011

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

Merge pull request #1072 from takluyver/i89
If object has a getdoc() method, use its return value (as long as it's a string) as the object's docstring.

Closes gh-89 (duplicate docstrings when objects have getdoc).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment