Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-135443: Sometimes Fall Back to __main__.__dict__ For Globals#135491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrentlyericsnowcurrently commentedJun 13, 2025
edited by bedevere-appbot
Loading

For several builtin functions, we now fall back to__main__.__dict__ for the globals
when there is no current frameand_PyInterpreterState_IsRunningMain() returns
true. This allows those functions to be run withInterpreter.call().

The affected builtins:

  • exec()
  • eval()
  • globals()
  • locals()
  • vars()
  • dir()

Comment on lines 2086 to 2090
if (_PyEval_GetFrame() != NULL) {
locals = _PyEval_GetFrameLocals();
}
PyThreadState *tstate = _PyThreadState_GET();
locals = _PyEval_GetGlobalsFromRunningMain(tstate);
Copy link
Contributor

@neoneneneoneneJun 15, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

_PyEval_GetFrameLocals() returns a new reference (leak), which is overwritten by_PyEval_GetGlobalsFromRunningMain(). Thus the fallback mechanism looks to be missing.

The same goes forbuiltin_vars().

ericsnowcurrently reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

@@ -1414,6 +1414,41 @@ def test_call_invalid(self):
with self.assertRaises(interpreters.NotShareableError):
interp.call(func, op, 'eggs!')

def test_callable_requires_frame(self):
# There are various functions tha require a current frame.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

a typo in the comment.

ericsnowcurrently reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

Comment on lines 1432 to 1436
notshareable = [
globals,
locals,
vars,
]
Copy link
Contributor

@neoneneneoneneJun 15, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If "notshareable" here means that the result of the functions cannot be pickled, couldNotShareableError differentiate the round-trip in the future? Also,interpreters.is_shareable() returnsFalse for bothglobals anddir, which might be confusing at first.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

@ericsnowcurrentlyericsnowcurrently added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelJun 16, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@ericsnowcurrently for commitc93f890 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135491%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelJun 16, 2025
@ericsnowcurrentlyericsnowcurrently merged commita450a0d intopython:mainJun 16, 2025
107 of 109 checks passed
@miss-islington-app
Copy link

Thanks@ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@ericsnowcurrentlyericsnowcurrently deleted the fix-interp-call-exec branchJune 16, 2025 23:34
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJun 16, 2025
…pythongh-135491)For several builtin functions, we now fall back to __main__.__dict__ for the globalswhen there is no current frame and _PyInterpreterState_IsRunningMain() returnstrue.  This allows those functions to be run with Interpreter.call().The affected builtins:* exec()* eval()* globals()* locals()* vars()* dir()We take a similar approach with "stateless" functions, which don't use anyglobal variables.(cherry picked from commita450a0d)Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
@bedevere-app
Copy link

GH-135593 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelJun 16, 2025
ericsnowcurrently added a commit that referenced this pull requestJun 16, 2025
gh-135593)For several builtin functions, we now fall back to __main__.__dict__ for the globalswhen there is no current frame and _PyInterpreterState_IsRunningMain() returnstrue.  This allows those functions to be run with Interpreter.call().The affected builtins:* exec()* eval()* globals()* locals()* vars()* dir()We take a similar approach with "stateless" functions, which don't use anyglobal variables.(cherry picked from commita450a0d, AKAgh-135491)Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
lkollar pushed a commit to lkollar/cpython that referenced this pull requestJun 19, 2025
…pythongh-135491)For several builtin functions, we now fall back to __main__.__dict__ for the globalswhen there is no current frame and _PyInterpreterState_IsRunningMain() returnstrue.  This allows those functions to be run with Interpreter.call().The affected builtins:* exec()* eval()* globals()* locals()* vars()* dir()We take a similar approach with "stateless" functions, which don't use anyglobal variables.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@neoneneneoneneneonene left review comments

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@ericsnowcurrently@bedevere-bot@neonene

[8]ページ先頭

©2009-2025 Movatter.jp