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

autodoc: Handling of "forward references" for typed functions/methods #8498

Closed
chrisjsewell opened this issue Nov 27, 2020 · 4 comments
Closed

Comments

@chrisjsewell
Copy link
Member

chrisjsewell commented Nov 27, 2020

Describe the bug

If a function/method/etc is typed with an object from another module in the package, this can lead to the reference to that object not yet being available, and thus the referencing fails.

To Reproduce

Create a python module in a package with an object:

package/other.py:

class MyClass:
   pass

create another module that references that object as a type:

package/main.py:

from .other import MyClass

def func(klass: MyClass) -> None:
   pass 

Then I guess dependent on the order of file parsing / syntax tree assessment, this can lead to:

package/main.py:docstring of package.main.func::py:class reference target not found: package.other.MyClass

Expected behavior

The reference for the type should be found.

Your project

I've encountered this in numerous projects, but most recently in aiidateam/aiida-core#4575

/Users/workuser/Codes/aiida-core/aiida/tools/graph/graph_traversers.py:docstring of aiida.tools.graph.graph_traversers.TraverseGraphOutput.links::py:class reference target not found: aiida.orm.utils.links.LinkQuadruple

Environment info

  • OS: Unix (any)
  • Python version: 3.8
  • Sphinx version: 3.2.1
  • Sphinx extensions: sphinx.ext.autodoc
@tk0miya
Copy link
Member

tk0miya commented Nov 28, 2020

Is package.other.MyClass documented? If not, Sphinx can't resolve the reference. Please add it to your document.

@tk0miya
Copy link
Member

tk0miya commented Dec 25, 2020

Now I'm closing this. Please feel free to reopen if you're still in trouble.
Thanks,

@ltalirz
Copy link

ltalirz commented Mar 9, 2021

yes, I believe this occurs also in cases where package.other.MyClass is documented.
Would it help if @chrisjsewell created a repository with a minimum working example to reproduce this?

@tk0miya
Copy link
Member

tk0miya commented Mar 9, 2021

Yes. It must be helpful!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 13, 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

3 participants