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

Methods in child classes can't natively reference inherited methods. #9130

Closed
bwoodsend opened this issue Apr 23, 2021 · 1 comment
Closed

Comments

@bwoodsend
Copy link

Describe the bug
This is halfway between a bug and a feature request (and probably not of high priority either way). The docstring in a child class can't cross-reference methods/attributes that it inherits using the native :meth:`inherited_method` syntax. Instead it has to use fully qualified referencing :meth:`~ParentClass.inherited_method` .

class Foo:
    def foo(self):
        """A docstring."""
        pass


class Bar(Foo):
    def uses_foo(self):
        """This cross reference to :meth:`foo`won't work.

        A fully qualified reference like :meth:`~Foo.foo` does work but gets
        tedious if the parent class if from another library and therefore needs
        the module name too.
        """
        pass

To Reproduce

I've put the above example, along with its autodoc stubs in an example repo.

git clone https://github.com/bwoodsend/sphinx-reference-issue.git
cd sphinx-reference-issue
pip install -U sphinx
sphinx-build -n docs/source docs/build

The last command should cause a warning about the failed cross-reference.

/.../sphinx-reference-issue/test.py:docstring of test.Bar.uses_foo:1: WARNING: py:meth reference target not found: foo

Expected behavior

I would like the :attr:`attribute` and :meth:`method` to reference the attribute/method from the parent class if that attribute/method has not been overloaded by the child class. i.e In my example above, the cross references in Bar.uses_foo() should both link to Foo.foo().

Environment info

  • OS: Linux 5.11.6-1-MANJARO
  • Python version: 3.9
  • Sphinx version: 3.5.4
  • Sphinx extensions: [sphinx.ext.autodoc]
  • Extra tools: None
@tk0miya
Copy link
Member

tk0miya commented Apr 24, 2021

Thank you for reporting. At present, it's not supported. The reference :meth:`inherited_method` tries to search Bar.instance_method only. It does not search Foo.instance_method. Please use the "fully qualified referencing" workaround.

Note: This is the same as #272. So I'm closing this as duplicated.

@tk0miya tk0miya closed this as completed Apr 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 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

2 participants