Skip to content

Conversation

@eugenetriguba
Copy link
Contributor

@eugenetrigubaeugenetriguba commented May 25, 2024

Currently, we expose some of the internal imports and definitions on REPL startup in the new REPL.

% ./python.exe Python 3.14.0a0 (heads/main:de19694cfb, May 25 2024, 07:36:35) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> dir() ['CAN_USE_PYREPL', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'interactive_console', 'os', 'sys'] 

This PR addresses that by moving the implementation of main into its own separate module and only importing in what is needed to get it running. Now, we see there is only interactive_console in addition to the dunder attributes shown in the global scope on startup.

% ./python.exe Python 3.14.0a0 (heads/main:de19694cfb, May 25 2024, 07:36:35) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> dir() ['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'interactive_console'] 

@eugenetrigubaeugenetriguba changed the title gh-118908: Limit exposed globals in new REPLgh-118908: Limit exposed globals from internal imports and definitions on new REPL startupMay 25, 2024
Copy link
Member

@pablogsalpablogsal left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @eugenetriguba but unfortunately I don't think this is the proper fix for this issue. The proper fix is to properly filter the namespace here:

mainmodule=mainmoduleor__main__

And to use a clean one when it makes sense (when not running with -i) or filtering the stuff we don't want.

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ambvambv added the topic-repl Related to the interactive shell label May 31, 2024
@pablogsalpablogsal added the needs backport to 3.13 bugs and security fixes label Jun 11, 2024
Copy link
Member

@lysnikolaoulysnikolaou left a comment

Choose a reason for hiding this comment

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

Looks good! 🎉

Just a couple of comments.

Copy link
Member

@lysnikolaoulysnikolaou left a comment

Choose a reason for hiding this comment

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

Just one final comment and this is good to go! Thanks both!

Copy link
Member

@lysnikolaoulysnikolaou left a comment

Choose a reason for hiding this comment

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

LGTM!

@pablogsalpablogsal merged commit 86a8a1c into python:mainJun 11, 2024
@miss-islington-app
Copy link

Thanks @eugenetriguba for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2024
…nitions on new REPL startup (pythonGH-119547) (cherry picked from commit 86a8a1c) Co-authored-by: Eugene Triguba <eugenetriguba@gmail.com>
@bedevere-app
Copy link

GH-120362 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13 bugs and security fixes label Jun 11, 2024
pablogsal pushed a commit that referenced this pull request Jun 11, 2024
@eugenetriguba
Copy link
ContributorAuthor

@pablogsal Been a bit busy and was unable to get back to this, thank you for finishing it off and the feedback 🙂

@encukou
Copy link
Member

Since this commit, the "AMD64 Debian PGO 3.x" buildbot has started reporting a runaway process, e.g. here:

1:17:07 load avg: 20.12 [453/478/1] test_pyrepl failed (env changed) (37.4 sec) test_empty (test.test_pyrepl.test_input.KeymapTranslatorTests.test_empty) ... ok test_push_character_key (test.test_pyrepl.test_input.KeymapTranslatorTests.test_push_character_key) ... ok test_push_character_key_with_stack (test.test_pyrepl.test_input.KeymapTranslatorTests.test_push_character_key_with_stack) ... ok [...] test_exposed_globals_in_repl (test.test_pyrepl.test_pyrepl.TestMain.test_exposed_globals_in_repl) ... skipped 'pyrepl not available' [...] ---------------------------------------------------------------------- Ran 116 tests in 35.634s OK (skipped=2) Warning -- reap_children() reaped child process 3457256 == Tests result: ENV CHANGED then ENV CHANGED == 

mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-replRelated to the interactive shell

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@eugenetriguba@encukou@danielhollas@pablogsal@lysnikolaou@ambv