Skip to content

autosummary: fix name resolution when a class and module differ only by case - #14598

Open
larsoner wants to merge 1 commit into
sphinx-doc:masterfrom
larsoner:fix-autosummary-case-insensitive
Open

larsoner wants to merge 1 commit into
sphinx-doc:masterfrom
larsoner:fix-autosummary-case-insensitive

Conversation

@larsoner

@larsoner larsoner commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Originally found this when trying to document the class mne.Dipole when there is also the mne.dipole module. Sphinx would try to import mne.Dipole first, which could succeed on a case-insensitive filesystem (and was observed on Windows) but errantly import mne.dipole (so all the class attributes etc. were missing). This PR changes the order: look for a (case-sensitive) sys.modules existence (for intermediate components), then an attribute getattr(mne, "Dipole"), and then try an import.

This PR mocks the case-insensitive import behavior via a sys.meta_path finder so it's reproducible on all platforms and more easily tested. It also does a combined test with autosummary_filename_map, which helps with a similar problem. Two tests are red on master but pass on this PR, and the third (test_import_by_name_attribute_shadows_module) is there to make sure an existing case on master (a function shadowing its own module like from .util import util) isn't broken.

References

Closes #11362 (mine -- 3+ years ago, now I could finally look into it more deeply!)

AI Disclosure

Claude Fable 5 was used to write the implementation, tests, and changelog entry. I reviewed and validated the implementation (e.g., suggesting a combined test to hit the autosummary_filename_map path as well).

This branch has not been deployed

No deployments
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.

autodoc and autosummary failing when class and module have the same name

1 participant