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

Forward references guarded by typing.TYPE_CHECKING raises warnings with Sphinx 1.8.0/1.8.1 #5480

Closed
jenshnielsen opened this issue Sep 23, 2018 · 4 comments

Comments

@jenshnielsen
Copy link
Contributor

Building the documentation that uses the typing.TYPE_CHECKING constant to break import cycles as suggested in the mypy docs here results in a Warning with 1.8.0/1 that was not raised with 1.7.9. I am trying to build the docs of our project that unfortunately has a circular reference of this type warning free.

This is similar to #4072 but a new change with Sphinx 1.8.0 that does not relate to the use of the sphinx-autodoc-typehints extension.

I believe that the output is functionally identical to 1.7.9 but now raises a warning that was silent before. Raising the warning is probably correct since the conditionally imported type annotation was never expanded correctly. I have not looked into pep563 style postponed evaluation

Procedure to reproduce the problem

Build html docs of the attached project with make html

Error logs / results

A warning of an Ignored NameError is raised

WARNING: Invalid type annotation found on <function AClass.__init__ at 0x0000028BD9998620>. Ignored: NameError("name 'B' is not defined",)

Expected results

Build without warnings

Reproducible project / your project

The latest tip of https://github.com/jenshnielsen/sphinx_issue builds without warnings with
Sphinx 1.7.9 but produces Warning with 1.8.0/1. This is a slightly modified version of the code used
to reproduce #4072

Environment info

  • OS: Windows 10
  • Python version: 3.6.6
  • Sphinx version: 1.8.1
@tk0miya tk0miya added this to the 1.8.2 milestone Sep 29, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 15, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 15, 2018
tk0miya added a commit that referenced this issue Oct 16, 2018
Fix #5480: autodoc: unable to find type hints for unresolvable Forward references
@tk0miya
Copy link
Member

tk0miya commented Oct 16, 2018

Fixed by #5535.
Thank you for reporting.

@tk0miya tk0miya closed this as completed Oct 16, 2018
@jenshnielsen
Copy link
Contributor Author

@tk0miya Thanks

@lyndsysimon
Copy link

lyndsysimon commented Nov 12, 2018

A note for future people who come across this - circular imports can still be an issue if using sphinx-autodoc-typehints version 1.4.0, because it sets typing.TYPE_CHECKING = True. The most recent version released to PyPI without this change is 1.3.0.

Their README suggests a solution - to import the module instead of the object you're using in the annotation.

@jacebrowning
Copy link

Additional note to future readers, sphinx-autodoc-typehints >= 1.5.0 allows you to disable type checking via set_type_checking_flag = False in conf.py to silence this warning.

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

4 participants