FIX: don't evaluate annotations when collecting signature parameters (Python 3.14 / PEP 649) - #700
Merged
Merged
Conversation
Contributor
Author
|
@jarrodmillman @larsoner It would be appreciated if that fix can fit in the |
Collaborator
|
Looks reasonable to me! Could you add a regression test? Maybe something like (suggested by Claude Opus 5): @pytest.mark.skipif(sys.version_info < (3, 14), reason="PEP 649 lazy annotations")
def test_signature_params_with_typechecking_only_annotation():
ns = {}
exec("def func(a, b=1, *args, **kwargs) -> OnlyUnderTypeChecking: ...", ns)
assert Validator(get_doc_object(ns["func"])).signature_parameters == (
"a", "b", "*args", "**kwargs",
) |
Contributor
Author
|
Done: 0d20d54 |
larsoner
approved these changes
Jul 27, 2026
Collaborator
|
Thanks @mscheltienne ! |
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.
Fix suggested by Claude Opus 4.8 on failures observed today while modernizing our SW stack to 3.14+.
On Python 3.14, PEP 649 evaluates annotations lazily and
inspect.signature()now resolves them (VALUE format) when building the signature. As a result, running numpydoc validation on a callable whose signature annotation references a name that's only importable underTYPE_CHECKINGraisesNameError— a common pattern for typing-only imports, especially in modules that can't usefrom __future__ import annotations.Validator.signature_parametersguardsinspect.signature()only against(TypeError, ValueError), so theNameErrorpropagates and aborts the Sphinx build (the autodoc-process-docstring handler raises).signature_parametersonly uses parameter names and kinds, never the annotation values, so this evaluation is unnecessary. On Python 3.14+ it now introspects withannotationlib.Format.FORWARDREF, which returns unresolved forward references asForwardRefobjects rather than evaluating (and crashing on) them. Behaviour on Python < 3.14 is unchanged.Reproducer (Python 3.14):
Validating build previously raised
NameError: name 'Thing' is not defined; with this change it validates cleanly.