fix: handle PEP 649 NameError in inspect.signature on Python 3.14#361
Merged
Abhijeet Prasad (AbhiPrasad) merged 3 commits intomainfrom Apr 29, 2026
Merged
Conversation
On Python 3.14, `inspect.signature(fn)` defaults to VALUE format, which eagerly evaluates annotations. Annotations that reference TYPE_CHECKING- only imports raise NameError. The bare excepts in `_call_user_fn_args` and the hooks-detection check then dropped parameter introspection, causing tasks that take `hooks` to be called without it and crash with `TypeError: missing 1 required positional argument: 'hooks'`. Add a shared `get_signature` helper in `util.py` that uses `annotationlib.Format.FORWARDREF` on 3.14+ so unresolvable names become ForwardRef objects without raising. Apply it in framework.py and in the `@traced` decorator in logger.py. Adds a 3.14-only regression test. Fixes #263 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Abhijeet Prasad (AbhiPrasad)
approved these changes
Apr 29, 2026
Merged
Abhijeet Prasad (AbhiPrasad)
added a commit
that referenced
this pull request
Apr 29, 2026
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.
Summary
Fixes #263. On Python 3.14 (PEP 649),
inspect.signature(fn)defaults to VALUE format and eagerly evaluates annotations. Functions withTYPE_CHECKING-only imports in their annotations raiseNameError, the bareexceptblocks inframework.pydropped parameter introspection, and tasks taking ahooksargument crashed withTypeError: missing 1 required positional argument: 'hooks'.get_signature(fn)helper inutil.pythat usesannotationlib.Format.FORWARDREFon Python 3.14+ (and vanillainspect.signatureon 3.10–3.13). FORWARDREF wraps unresolvable names asForwardRefobjects without raising; we only inspect parameter names/kinds, so annotation values are never needed.framework._call_user_fn_argsand the hooks-detection signature call in_run_evaluator_internal_impl.@traceddecorator inlogger.py, which had the same latent issue (degraded I/O tracing rather than a crash, but same root cause).hooksannotation references aTYPE_CHECKING-only import.Test plan
test_hooks_with_type_checking_only_annotationfails on the unfixed code (saw_hooks == []) and passes after the fix.nox -s test_core— 443 passed, 56 skipped, 12 xfailed.pytest src/braintrust/test_framework.py src/braintrust/test_logger.py— 162 passed, 1 skipped (the new <3.14 guard).TypeError) before, hooks correctly injected.🤖 Generated with Claude Code