Repository navigation
Conversation
Author
|
Heads-up on the red CI: the failing jobs here ( The checks that exercise this change all pass: |
…ction
The parameter name differs between CPython builds and patch releases
('tuple' vs 'time_tuple'), so a version-range check cannot be reliable.
Derive the expected name from the running interpreter's docstring,
which is exactly what autodoc renders.
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.
Resolves #14354
What
When autodoc imports a PEP 561
.pyistub file for a native module (via_find_type_stub_spec/_StubFileLoader), it now executes the stub as if it began withfrom __future__ import annotations— which is exactly how PEP 484 defines stub-file semantics ("The type checker is required to treat annotations in stub files as if they were always evaluated withfrom __future__ import annotations"). Previously the stub was compiled and executed as a plain module, so a forward reference in an annotation raisedNameErrorat import time:The implementation compiles the stub source with the
CO_FUTURE_ANNOTATIONScompiler flag instead ofspec.loader.exec_module, so annotations stay lazily-evaluated strings and the module namespace is populated exactly as before otherwise.Testing
tests/roots/test-ext-apidoc-duplicates/fish_licence/halibut.pyi(previously empty) now contains a class with a self-referencing annotation, which reproduces the reportedNameErroronmain.test_import_native_module_stubs_defer_annotationsasserts the import succeeds and the annotation is preserved as a deferred string ('Fish').mainwith the exact reported error (NameError: name 'Fish' is not defined) and passes with this change.ruff checkandruff format --check(pinned 0.14.9) are clean. The remainingtest_ext_autodocfailures in my local run (test_overload3,test_final,test_autodoc_pep695_type_alias,test_cfunction) are identical on unmodifiedmainin this environment and unrelated to this change.