Skip to content

Add option to use member listing for attributes #161

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

Merged
merged 6 commits into from
Apr 17, 2019

Conversation

jorisvandenbossche
Copy link
Contributor

Related to the discussion in #106 (comment).
There was not really agreement on the way forward, but opening this PR to more easily show what my proposed change would be, and to show that it a minor change.
It does add yet another entry to the option list, that is true, but code wise everything is already there.

@jorisvandenbossche jorisvandenbossche force-pushed the attributes_as_param_list branch from f012981 to 5c2f4fe Compare March 30, 2018 07:47
Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

Need to double check that we summarise the docstring in this case such that we won't include any block structure (e.g. tables, lists) which is why we moved back to param lists

@jorisvandenbossche
Copy link
Contributor Author

Need to double check that we summarise the docstring in this case such that we won't include any block structure (e.g. tables, lists) which is why we moved back to param lists

I don't really follow your comment on what or how to check (I don't know the history of why the move from member list to param list was done. I thought this was for visual reasons).
But note that the exact same code is used to generate the methods listing as well, so if there is no problem in that case, I wouldn't expect problems here.

@jnothman
Copy link
Member

jnothman commented Apr 2, 2018 via email

@jorisvandenbossche
Copy link
Contributor Author

Ah, OK, I understand what you mean: the description of the attributes if they are listed in the actual class docstring. But, I think the "member listing" will ignore those descriptions, as it purely uses autosummary table, and autosummary will get the description from the first line of the docstring of the attribute.

I can add a test that it is indeed not used, like:

In [22]:     class Foo:
    ...:         """
    ...:         Class docstring.
    ...:         
    ...:         Attributes
    ...:         ----------
    ...:         an_attribute : type
    ...:             Another description with a list that is not used:
    ...:     
    ...:             * item 1
    ...:     
    ...:         """
    ...:         
    ...:         @property
    ...:         def an_attribute(self):
    ...:             """Test attribute"""
    ...:             return None
    ...:     

In [23]: print(str(SphinxClassDoc(Foo, config=cfg)))

Class docstring.













.. rubric:: Attributes

.. autosummary::
   :toctree:

   an_attribute

@larsoner
Copy link
Collaborator

larsoner commented Apr 2, 2019

@jorisvandenbossche would this allow you to do less monkey-patching of numpydoc for pandas? It looks like if you add the test you mention above, plus a bit of documentation of the new parameter, this should be mergeable.

@jorisvandenbossche
Copy link
Contributor Author

Yes, that would certainly help for the pandas side. Will try to add a test and docs in the coming days.

@larsoner larsoner added this to the v0.9.0 milestone Apr 11, 2019
@jnothman
Copy link
Member

I don't know whether this is the right solution but I suppose can accept it...

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

This also needs documentation among the other config options

@jorisvandenbossche
Copy link
Contributor Author

I don't know whether this is the right solution

What alternative would you propose?

In any case, from the pandas docs point of view (or at least my view point of it :)), the change that numpydoc was a regression. And it would be nice to at least have some way to keep the old appearance.

Copy link
Collaborator

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

To visually confirm what this does, this sort of page:

Screenshot from 2019-04-15 10-25-41

When setting numpydoc_attributes_as_param_list = False ends up looking like:

Screenshot from 2019-04-15 10-25-43

Seems like a reasonable option to me -- we might even switch to it -- and it's tested and documented, so +1 for merge from me.

@jorisvandenbossche
Copy link
Contributor Author

Yep, that's indeed the goal.

There is some logic in there (already existing, as I only restored how it was before in numpydoc) that gets the summary information either from the attribute's docstring, or either from the listing of the attribute in the class docstring. And in the second case, it seems to add the type information in the summary line (eg the "(dict)" in "info (dict) Measurement info" in the above picture). It could be an enhancement that this type info is also added in the first case (if it is listed in the class docstring of course). But since we don't have such cases in pandas, I didn't look into that.

@larsoner
Copy link
Collaborator

It could be an enhancement that this type info is also added in the first case

I'm okay with this being a follow-up PR

@rgommers
Copy link
Member

LGTM too and have tested on NumPy and SciPy docs. So in it goes. Thanks @jorisvandenbossche, @jnothman and @larsoner

@rgommers rgommers merged commit c2e8b8f into numpy:master Apr 17, 2019
@jorisvandenbossche jorisvandenbossche deleted the attributes_as_param_list branch April 18, 2019 08:03
@jorisvandenbossche
Copy link
Contributor Author

Thanks!

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.

4 participants