-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix 'Alias for field number X' problem with NamedTuples #527
Conversation
def _should_skip_member(name, klass): | ||
if ( | ||
# Namedtuples should skip everything in their ._fields as the | ||
# docstrings for each of the members is: "Alias for field number X" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work properly with #257 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with code from this comment, using
.. autoclass:: mypkg.Foo
:members:
that outputs:
does that answer to the question?
Edit: Added also the methods to the screenshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, thank you!
As a side note, it might be cleaner to have all "should_skip_member" -type of logic under one method. Right now there is not name.startswith("_") # <----- this
and not self._should_skip_member(name, self._cls)
and ( # <--------- this
func is None
or isinstance(func, (property, cached_property))
or inspect.isdatadescriptor(func)
)
and self._is_show_member(name)
...
def _is_show_member(self, name):
if self.show_inherited_members:
return True # show all class members
if name not in self._cls.__dict__: # <------- and perhaps this?
return False
return True which could be moved under one place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fohrloop ! I took the liberty of pushing up a test that fails on main
and passes after this change. This does indeed handle the duplication of the named fields mentioned in #257 .
PS; I was surprised to learn that there is no way to do isinstance
checks with named tuples - you learn something new everyday!
Thanks @rossbar for the test! Let me know if there's need for additional tests. For example, could it be tested that namedtuple with some custom docs in the params like this works as expected:
It was tested manually, but I don't know if it would be beneficial to have such automated test, too. Not sure how to implement that one, though. Is there something else that should be done here? Does the code need refactoring..? Or something else? |
That's a good idea, but shouldn't be a blocker for this PR. I'll try to add one today if I have time but don't wait on me - if someone pushes the green button in the meantime that's a positive outcome!
No other action necessary IMO - this is good to go. The only reason I didn't merge it myself is because I pushed up some code, so someone should have an opportunity to take a look at that. If it's not in by this evening I'll merge it! |
A day late, but I think I managed to design a test that captures your last comment @fohrloop - take a look and LMK what you think. If it looks correct to you I'll go ahead and merge! |
@rossbar awesome, thanks! It seems to test well that the
On the side note I don't fully undestand why the |
This is because they are included under the I think all the bases are now covered, so I'll go ahead and get this in, but if there are other corner-cases related to namedtuple/dataclasses, please don't hesitate to continue fleshing them out! |
myst_parser compatibilityI just did some tests with this using numpydoc 1.7.0rc0.dev0 installed from latest master (commit 46f532a):
It turns out that if you use This works: #conf.py
extensions = [
"numpydoc",
"myst_parser",
...
] This will not work: #conf.py
extensions = [
"myst_parser",
"numpydoc",
...
] (just commenting this here so that if someone has problems with this they know what to look at) |
This has a fix for NamedTuple documentation (numpy/numpydoc#527)
Thanks for bringing this up @fohrloop - this is worth it's own, separate issue here (and potentially with |
Yeah I'm not sure if this is an "issue" or just a feature. Not sure what And it's likely that this could/should be solved in myst_parser side as it's the one first in the list when there are problems. |
Fixes #257