Skip to content
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

Automatic :noindex: for sub-objects #7871

Open
outkine opened this issue Jun 25, 2020 · 4 comments
Open

Automatic :noindex: for sub-objects #7871

outkine opened this issue Jun 25, 2020 · 4 comments
Labels
type:enhancement enhance or introduce a new feature

Comments

@outkine
Copy link

outkine commented Jun 25, 2020

In my documentation, I list an abridged version of several previously-defined classes. In order to prevent duplicate indexing, I assumed that I would only need one :noindex: for each:

.. class:: State
    :noindex:

    .. attribute:: turn_num
    .. attribute:: our_team
    .. method:: obj_by_coords(coords)

.. class:: Obj
    :noindex:

    .. attribute:: id
    .. attribute:: coords
    .. attribute:: obj_type

...but this produces warnings:

WARNING: duplicate object description of State.our_team, other instance in api, use :noindex: for one of them
WARNING: duplicate object description of State.obj_by_coords, other instance in api, use :noindex: for one of them
etc

The solution is very verbose:

.. class:: State
    :noindex:

    .. attribute:: turn_num
        :noindex:
    .. attribute:: our_team
        :noindex:
    .. method:: obj_by_coords(coords)
        :noindex:

.. class:: Obj
    :noindex:

    .. attribute:: id
        :noindex:
    .. attribute:: coords
        :noindex:
    .. attribute:: obj_type
        :noindex:

It seems to me like it would always make sense to automatically apply :noindex: to all the children of a parent with :noindex:. Am I missing something?

@outkine outkine added the type:enhancement enhance or introduce a new feature label Jun 25, 2020
@jakobandersen
Copy link
Contributor

I completely agree that noindex should apply recursively, and even label this a bug. Depending on the domain it may not even be possible to not apply it recursively (see #7052 for some related discussion on noindex).

@tk0miya
Copy link
Member

tk0miya commented Jun 26, 2020

I guess it is designed to put a class definition to multiple documents or sections. For example, python-doc describes object class in multiple sections:
https://docs.python.org/3/reference/datamodel.html#basic-customization
https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access
https://docs.python.org/3/reference/datamodel.html#implementing-descriptors

@outkine
Copy link
Author

outkine commented Jun 29, 2020

@tk0miya That makes sense, but my use case is slightly different. I have an "API" page with the complete list of classes and methods, and then I display an abridged version of those classes on the "Getting Started" page. So, in a way, I'm using :noindex: as a way of "quoting" objects defined elsewhere. Not sure if there is a better solution for this.

@jakobandersen
Copy link
Contributor

@tk0miya That makes sense, but my use case is slightly different. I have an "API" page with the complete list of classes and methods, and then I display an abridged version of those classes on the "Getting Started" page. So, in a way, I'm using :noindex: as a way of "quoting" objects defined elsewhere. Not sure if there is a better solution for this.

I suggest adding an alias directive, similar to those for the C++ (and as of a few minutes ago, also the C) domain. It is meant exactly for this purpose.
I'm not familiar with the internals of the Python domain, but one implementation route is:

  • In add_target_and_index, save signatures in the domain data so it is a available for xref lookups.
  • Splice out the signature-to-node generation from handle_signature so it can be utilized elsewere.
  • Add the new directive which basically takes a list of names as argument (names in the same way as those given as a xref).
  • In the post-transform for the alias directive, look up the xrefs and replace them with the signature. Here the name in the signature should be a pending_xref to the actual declaration, instead of the usual add_name.

@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

4 participants