Skip to content

Explicitly re-export top-level API names for mypy --no-implicit-reexport - #14076

Open
Motaghi wants to merge 4 commits into
explosion:masterfrom
Motaghi:fix/13246
Open

Motaghi wants to merge 4 commits into
explosion:masterfrom
Motaghi:fix/13246

Conversation

@Motaghi

@Motaghi Motaghi commented Nov 12, 2026 •

Copy link
Copy Markdown

Description

With mypy --strict or --no-implicit-reexport, import spacy; spacy.prefer_gpu() fails with Module "spacy" does not explicitly export attribute "prefer_gpu", and the same happens for the other names spacy/__init__.py imports for users. Fixes #13246.

Those imports now use the X as X form that mypy treats as an explicit re-export: the four names under the "imported as part of the API" comment (Config, prefer_gpu, require_cpu, require_gpu) plus the documented info, explain, registry and Language. Nothing changes at runtime and the rest of the module is left alone. __version__ has the same problem; I can add it if you want it covered too. #13721 adds an __all__ list to the same file as part of lazy CLI loading, which would also cover these names. If it lands first, this reduces to the regression test; if this lands first, #13721 needs a small rebase.

The new test in spacy/tests/test_ty.py runs mypy (already in requirements.txt) on a three-line consumer that imports all eight names and calls spacy.prefer_gpu(). On master it reports nine export errors, and with the change it passes; it skips where mypy is not installed. It was tested with the rest of test_ty.py on macOS, Python 3.11, against both the checkout's source for type checking and a 3.8.17 wheel with these edits applied, since there was no local Cython build. Changed-file mypy, Ruff formatting and import ordering pass. The full suite is left to CI.

I used Codex (gpt-6.1-sol) to help write the patch and test and to run the checks above, and Claude Opus 5.5 reviewed the change independently. I've read and verified the diff myself.

Types of change

Bug fix for type checking. No runtime change.

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

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.

[mypy] Module "spacy" does not explicitly export attribute "prefer_gpu" when using --no-implicit-reexport

1 participant