Skip to content

Added try-catch for autodoc mock-import#89

Open
RobertoRoos wants to merge 2 commits into
mainfrom
bugfix/autodoc-mock-import
Open

Added try-catch for autodoc mock-import#89
RobertoRoos wants to merge 2 commits into
mainfrom
bugfix/autodoc-mock-import

Conversation

@RobertoRoos

@RobertoRoos RobertoRoos commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

Resolving #82 (again...)

This is the suggestion of @lucc , posted here: #82 (comment)

@RobertoRoos RobertoRoos self-assigned this Mar 7, 2026
@codecov

codecov Bot commented Mar 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.15%. Comparing base (528aa98) to head (4e8f1c4).

Files with missing lines Patch % Lines
sphinxarg/ext.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   50.19%   50.15%   -0.04%     
==========================================
  Files          18       18              
  Lines        1289     1292       +3     
  Branches      262      262              
==========================================
+ Hits          647      648       +1     
- Misses        598      600       +2     
  Partials       44       44              
Flag Coverage Δ
unittests 49.92% <50.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread sphinxarg/ext.py
Comment on lines +22 to +27
try:
from sphinx.ext.autodoc.mock import mock
except ImportError:
from sphinx.ext.autodoc import mock
# A persistent bug in sphinx / autodoc causes problems during importing (#82)

@RobertoRoos RobertoRoos Mar 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm a little in doubt now. I feel the intended method to import is the short version:

from sphinx.ext.autodoc import mock

So maybe we should prioritize that one. If for no other reason then to prevent us being the cause of an import error for the next package.

EDIT: I changed it but let's see what the bosses say over at sphinx-doc/sphinx#14333

@dvzrv

dvzrv commented Jun 16, 2026

Copy link
Copy Markdown

FYI: We are still/again seeing this issue with khard 0.21.0, sphinx 9.1.0 when trying to build the package for Arch Linux: lucc/khard#356

@RobertoRoos RobertoRoos force-pushed the bugfix/autodoc-mock-import branch from 88cd1f0 to 46a37d2 Compare June 25, 2026 06:34
@RobertoRoos RobertoRoos marked this pull request as ready for review June 25, 2026 06:34
@RobertoRoos

RobertoRoos commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

I want to merge this try-catch import, I think that should be future proof even if Sphinx rearranged their module structure.
@dvzrv would you have a chance to test this branch on your project to see if it actually resolves the bug?

With pip you can do this with an install like this:

pip install git+https://github.com/sphinx-doc/sphinx-argparse.git@bugfix/autodoc-mock-import

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.

2 participants