Skip to content

Conversation

@seberg
Copy link
Member

@seberg seberg commented Apr 14, 2021

This ensures that help(np.dtype) produces a result. I am not
exactly sure why it picks up __doc__ from the dict instead of
tp_doc right now. It probably is due to the combination of
inheritance and the fact that the dict always includes None
and gets preference during inheritance.
(That probably makes a lot of sense to not inherit the type
docstring by default.)

Modifying the dictionary directly is not really good style, either,
but hopefully works.

Closes gh-18740

@seberg
Copy link
Member Author

seberg commented Apr 14, 2021

OK, this doesn't quite seem to work, because it overshadows the getset of the instance? Hmmm...

EDIT: Well, maybe the solution is to add a special case just for np.dtype right now...

@eric-wieser
Copy link
Member

Are metaclasses related at all here, or is this just a heap type problem?

@seberg
Copy link
Member Author

seberg commented Apr 15, 2021

@eric-wieser yeah, that would make sense, but I am not setting the HEAPTYPE flag on np.dtype right now, which is why I am confused. So my guess was that inheritance causes the __dict__ value to be used instead of the tp_doc one (although I am not quite sure where that happens in pythons typeobject.c

@charris
Copy link
Member

charris commented Apr 21, 2021

close/reopen

@charris charris closed this Apr 21, 2021
@charris charris reopened this Apr 21, 2021
@charris charris added 25 - WIP 09 - Backport-Candidate PRs tagged should be backported labels Apr 30, 2021
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label May 17, 2021
This ensures that `help(np.dtype)` produces a result.  I am not
exactly sure why it picks up `__doc__` from the dict instead of
`tp_doc` right now. It probably is due to the combination of
inheritance and the fact that the dict always includes `None`
and gets preference during inheritance.
(That probably makes a lot of sense to not inherit the `type`
docstring by default.)

Modifying the dictionary directly is not really good style, either,
but hopefully works.

Closes numpygh-18740
@seberg seberg force-pushed the dtype-doc-missing branch from abf8ffd to 9975cc8 Compare October 4, 2021 18:50
@seberg
Copy link
Member Author

seberg commented Oct 4, 2021

After chasing around how ufuncs add docstrings (we have a function to do it via Python, which claims it is used but is not actually used)...

The only thing that was necessary here was to only put the doc-string into the dict only if the dict contains None for __doc__ (which means PyType_Read() probably filled it in automatically.

This actually means/fixes that np.float16(3.).__doc__ also correctly shows the np.float16.__doc__ now.

@seberg seberg added 09 - Backport-Candidate PRs tagged should be backported and removed 25 - WIP labels Oct 4, 2021
Copy link
Member

@WarrenWeckesser WarrenWeckesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @seberg. I noticed one small typo.

Co-authored-by: Warren Weckesser <[email protected]>
@WarrenWeckesser WarrenWeckesser merged commit fb2509c into numpy:main Oct 6, 2021
@WarrenWeckesser
Copy link
Member

Thanks @seberg.

@seberg seberg deleted the dtype-doc-missing branch October 6, 2021 00:40
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dtype missing docstrings since 1.20.1

4 participants