Propagate __future__ compiler flags in exec/eval/compile replacements#1008
Merged
emeryberger merged 3 commits intomasterfrom Feb 24, 2026
Merged
Conversation
…#1007) The replacement wrappers for exec(), eval(), and compile() break the implicit compiler flag inheritance chain. When code with `from __future__ import annotations` calls exec() with a string source, the wrapper recompiles it without the annotations flag, causing type annotations to be evaluated at runtime instead of being kept as strings. Fix all three wrappers to extract __future__ flags from the real caller's code object and pass them explicitly to compile() with dont_inherit=True. Fixes #1007 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5a44086 to
70af16c
Compare
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
__future__compiler flags from the real caller's contextfrom __future__ import annotationsthat callsexec()with a string source gets compiled without the annotations flag, causing type annotations to be evaluated at runtime instead of being kept as stringsexec,eval,compile)Test plan
scalene run --profile-all --profile-exclude site-packages scatest.pyno longer raisesNameError: name 'DBAPIConnection' is not definedFixes #1007
🤖 Generated with Claude Code