Skip to content

Always import from sphinx.ext.autodoc.mock module instead of relying on implicit import resolution#160

Open
dionhaefner wants to merge 2 commits intoclick-contrib:masterfrom
dionhaefner:master
Open

Always import from sphinx.ext.autodoc.mock module instead of relying on implicit import resolution#160
dionhaefner wants to merge 2 commits intoclick-contrib:masterfrom
dionhaefner:master

Conversation

@dionhaefner
Copy link
Copy Markdown

@dionhaefner dionhaefner commented Feb 19, 2026

Summary

Fixes #159

The problem is that some extensions (like sphinx_autodoc_typehints) run this:

from sphinx.ext.autodoc.mock import mock

This causes sphinx_click to resolve its own import of mock differently, which uses:

from sphinx.ext.autodoc import mock

Before running from sphinx.ext.autodoc.mock import mock, this resolves to the mock function. After, it resolves to the mock module. This is an inherent property of the Python resolution mechanism where the module is added as an attribute of the parent module once imported.

The easiest fix to me is to side-step the issue and import from the sphinx.ext.autodoc.mock module explicitly, which is what this PR implements. This module has existed at least since Sphinx 4.0.0 (current minimum version of Sphinx) so should be backwards compatible.

Tasks

  • Added unit tests
  • Added documentation for new features (where applicable)
  • Added release notes (using reno)
  • Ran test suite and style checks and built documentation (tox)

Further details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sphinx.ext.autodoc.mock is a module and not callable

1 participant