Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
mypy --strictor--no-implicit-reexport,import spacy; spacy.prefer_gpu()fails withModule "spacy" does not explicitly export attribute "prefer_gpu", and the same happens for the other namesspacy/__init__.pyimports for users. Fixes #13246.Those imports now use the
X as Xform 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 documentedinfo,explain,registryandLanguage. 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.pyruns mypy (already inrequirements.txt) on a three-line consumer that imports all eight names and callsspacy.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 oftest_ty.pyon 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