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

PythonDomain.resolve_xref incorrectly matches ivars to class methods #2549

Closed
paulromano opened this issue May 16, 2016 · 15 comments
Closed

Comments

@paulromano
Copy link

This issue was originally described in a stackoverflow post and has gone unanswered for a while. If an :ivar: has the same name as a method in a different class, a cross reference is incorrectly created. Furthermore, if two classes have methods of the same name as the :ivar:, a warning is raised saying:
WARNING: more than one target found for cross-reference ...

@nicoddemus
Copy link

I'm having the exact same problem, is there a known workaround for that? I'm trying to build pytest's documentation with -W, and this is the only warning that I couldn't get rid of...

@paulromano
Copy link
Author

I still haven't found a workaround.

@nicoddemus
Copy link

I had to change from ivars in the dosctring to inline comments as can be seen here, in case others find this useful.

@b1naryth1ef
Copy link

b1naryth1ef commented Oct 5, 2016

Bump, also having this issue.

@rouge8
Copy link
Contributor

rouge8 commented Nov 18, 2016

I'm getting this same error with :param:

@riccardomurri
Copy link

me too -- seeing the issue also with :param list foo:

@rouge8
Copy link
Contributor

rouge8 commented May 2, 2017

Still no good workaround for this 😕

vvmruder added a commit to openoereb/pyramid_oereb that referenced this issue May 10, 2017
…build, cant fix cross attribute warnings due to still open bug in sphinx: sphinx-doc/sphinx#2549
@goodspark
Copy link

Also seeing this with :type foo: list

@mzjn
Copy link

mzjn commented Jul 5, 2017

It is perhaps not a "good" workaround, but this monkey patch works: https://stackoverflow.com/a/41184353.

@bilderbuchi
Copy link

bilderbuchi commented Aug 27, 2017

I'm seeing this with :attr:, where using

:attr:`~.current`

within docstrings finds current attributes/properties of other unrelated classes, too, and warns about them. Sometimes even the wrong one is preferred and thus linked in the output.

bilderbuchi added a commit to bilderbuchi/pymeasure that referenced this issue Aug 27, 2017
This can probably be reverted when sphinx-doc/sphinx#2549 is fixed.
cjermain pushed a commit to pymeasure/pymeasure that referenced this issue Aug 28, 2017
* Fix some sphinx make html warnings.

* Add pycomedi import guard if package is not available.

* Fix some broken references.

* Disambiguate attribute/methods in docstrings.

This can probably be reverted when sphinx-doc/sphinx#2549 is fixed.
@tk0miya tk0miya modified the milestones: 1.7, 1.8 Jan 14, 2018
openstack-gerrit pushed a commit to openstack/taskflow that referenced this issue May 10, 2018
Most notably, taskflow is hitting the sphinx issue
sphinx-doc/sphinx#2549 which causes a
spurious warning that breaks the build with -W.  There is a
workaround posted in
https://stackoverflow.com/questions/31784830/sphinx-ivar-tag-goes-looking-for-cross-references
to move :ivar: docstrings to inline comments on the member variable
itself.  This is not ideal because it causes the docs to render
differently from :ivar:, but until the sphinx bug is fixed it will
allow us to keep documenting the problematic variables.

There was also a problem with one of the doctests because the
output had changed.  That is now fixed.

I also noticed a typo in one of the parameter descriptions so that
is fixed too.

Change-Id: Ib44621f6c3ba2c5476ec430218a0449f9f45d18f
@MrCreosote
Copy link

:ivar: has the same name as a method in a different class

__slots__ seems to play into this as well:

foo.py:

class Foo:
    """
    :ivar id: thing
    """

    __slots__ = ['id']

bar.py:

class Bar:
    """
    :ivar id: thing
    """

    __slots__ = ['id']

log:

bar.py:docstring of bar.Bar:: WARNING: more than one target found for cross-reference 'id': bar.Bar.id, foo.Foo.id

Without __slots__ this doesn't happen. With __slots__, an id field appears at the bottom of the class documentation that wasn't there before, and if the classes are in different files, the ivar representation links to this field. However, if the classes are in the same file, then the second class's ivar representation will link to the first class's id field.

@tk0miya tk0miya added this to the 3.0.0 milestone Feb 7, 2020
grahamgower added a commit to grahamgower/stdpopsim that referenced this issue Feb 19, 2020
The error is:
```
stdpopsim/species.py:docstring of stdpopsim.Species::more than one target found for cross-reference 'id': stdpopsim.engines._MsprimeEngine.id, stdpopsim.slim_engine._SLiMEngine.id
```

See currently open sphinx issue for workaround.
sphinx-doc/sphinx#2549
grahamgower added a commit to grahamgower/stdpopsim that referenced this issue Feb 19, 2020
The error is:
```
stdpopsim/species.py:docstring of stdpopsim.Species::more than one target found for cross-reference 'id': stdpopsim.engines._MsprimeEngine.id, stdpopsim.slim_engine._SLiMEngine.id
```

See currently open sphinx issue for workaround.
sphinx-doc/sphinx#2549
grahamgower added a commit to grahamgower/stdpopsim that referenced this issue Feb 28, 2020
The error is:
```
stdpopsim/species.py:docstring of stdpopsim.Species::more than one target found for cross-reference 'id': stdpopsim.engines._MsprimeEngine.id, stdpopsim.slim_engine._SLiMEngine.id
```

See currently open sphinx issue for workaround.
sphinx-doc/sphinx#2549
@tk0miya tk0miya modified the milestones: 3.0.0, 3.1.0 Mar 14, 2020
ben-spiller added a commit to pysys-test/pysys-test that referenced this issue Apr 12, 2020
… ;

also rework improve the top level documentation for BaseRunner
ghost pushed a commit to torproject/stem that referenced this issue May 14, 2020
Sphinx attempts to create cross-references for attribute and variable names...

  sphinx-doc/sphinx#2549
  sphinx-doc/sphinx#3866

This results in numerous warnings of the form...

  WARNING: more than one target found for cross-reference 'digest'

Adapting a patch from the tickets above. Sphinx deprecated override_domain(),
so using add_domain() instead...

  https://www.sphinx-doc.org/en/2.0/extdev/appapi.html#sphinx.application.Sphinx.override_domain
@tk0miya tk0miya modified the milestones: 3.1.0, 3.2.0 May 30, 2020
@tk0miya tk0miya modified the milestones: 3.2.0, 3.3.0 Aug 2, 2020
@tk0miya tk0miya modified the milestones: 3.3.0, 3.4.0 Oct 5, 2020
ziransun added a commit to ziransun/wpt that referenced this issue Nov 19, 2020
Issue web-platform-tests#23081

This CL made the following changes:
[1] Upgrading Sphinx version to 3.3.1 to support python 3.5+
[2] Fixing bugs invoked during Py3 run.
    a) Replace reference of "index" in checklist.md with relative path for
       index.md. This is due to "more than one target found for cross-reference"
       error thrown by Sphinx referring to it. It's a known issue in
       sphinx (sphinx-doc/sphinx#2549)
    b) Fix Sphinx in third_party/pywebsocket3. A PR has been sent at
       GoogleChromeLabs/pywebsocket3#16

Note: Command to run with Python3 is: wpt --py3 build-docs
@hoefling
Copy link
Contributor

hoefling commented Nov 19, 2020

This randomly fixed the issue on my project. Not sure why.

:ivar ~.signature: The signature of this signature tree
:vartype ~.signature: str

With Sphinx 3.3, this fixed most of the duplicate crossref warnings for me, but even this wasn't enough in some cases. I had to also add the class name prefix:

# pkg.nn.tf_impl.py

class MyRNN(tf.keras.AbstractRNNCell):
    """
    :ivar tf.keras.layers.Dense ~MyRNN.layer1: :math:`l_1` layer.
    :ivar tf.keras.layers.Dense ~MyRNN.layer2: :math:`l_2` layer.
    """

# pkg.nn.torch_impl.py

class MyRNN(nn.Module):
    """
    :ivar torch.nn.Linear ~MyRNN.layer1: :math:`l_1` layer.
    :ivar torch.nn.Linear ~MyRNN.layer2: :math:`l_2` layer.
    :ivar torch.nn.Linear layer3: :math:`l_3` layer.
    """

I suppose this is because the classes have the same name, but are located in different modules.

Hexcles added a commit to web-platform-tests/wpt that referenced this issue Nov 26, 2020
Fixes #23081

This CL made the following changes:
[1] Upgrading Sphinx version to 2.4.4 to support python 3.5+
[2] Fixing bugs invoked during Py3 run.
    a) Replace reference of "index" in checklist.md with relative path for
       index.md. This is due to "more than one target found for cross-reference"
       error thrown by Sphinx referring to it. It's a known issue in
       sphinx (sphinx-doc/sphinx#2549)
    b) Fix Sphinx in third_party/pywebsocket3. A PR has been sent at
       GoogleChromeLabs/pywebsocket3#16

Note: Command to run with Python3 is: wpt --py3 build-docs

Co-authored-by: Robert Ma <[email protected]>
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Dec 4, 2020
…stonly

Automatic update from web-platform-tests
Run Sphinx generation in Python 3. (#26574)

Fixes #23081

This CL made the following changes:
[1] Upgrading Sphinx version to 2.4.4 to support python 3.5+
[2] Fixing bugs invoked during Py3 run.
    a) Replace reference of "index" in checklist.md with relative path for
       index.md. This is due to "more than one target found for cross-reference"
       error thrown by Sphinx referring to it. It's a known issue in
       sphinx (sphinx-doc/sphinx#2549)
    b) Fix Sphinx in third_party/pywebsocket3. A PR has been sent at
       GoogleChromeLabs/pywebsocket3#16

Note: Command to run with Python3 is: wpt --py3 build-docs

Co-authored-by: Robert Ma <[email protected]>
--

wpt-commits: da46f68d5b82371132b4f877e05b9b457de89af9
wpt-pr: 26574
sidvishnoi pushed a commit to sidvishnoi/gecko-webmonetization that referenced this issue Dec 10, 2020
…stonly

Automatic update from web-platform-tests
Run Sphinx generation in Python 3. (#26574)

Fixes #23081

This CL made the following changes:
[1] Upgrading Sphinx version to 2.4.4 to support python 3.5+
[2] Fixing bugs invoked during Py3 run.
    a) Replace reference of "index" in checklist.md with relative path for
       index.md. This is due to "more than one target found for cross-reference"
       error thrown by Sphinx referring to it. It's a known issue in
       sphinx (sphinx-doc/sphinx#2549)
    b) Fix Sphinx in third_party/pywebsocket3. A PR has been sent at
       GoogleChromeLabs/pywebsocket3#16

Note: Command to run with Python3 is: wpt --py3 build-docs

Co-authored-by: Robert Ma <[email protected]>
--

wpt-commits: da46f68d5b82371132b4f877e05b9b457de89af9
wpt-pr: 26574
@tk0miya tk0miya modified the milestones: 3.4.0, 3.5.0 Dec 19, 2020
@douglas-raillard-arm
Copy link

It is perhaps not a "good" workaround, but this monkey patch works: https://stackoverflow.com/a/41184353.

Sadly stopped working starting with Sphinx 3.4.0

@tk0miya
Copy link
Member

tk0miya commented Mar 16, 2021

Sorry for inconvenience long. Now #8638 will fix this bug. Thanks,

@tk0miya tk0miya closed this as completed Mar 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests