Skip to content

New REPL exposes its internal imports/definitions to top-level environment #118908

Done

Description

@chgnrdv

Bug report

Bug description:

Top-level scope now contains globals of _pyrepl.__main__:

Python 3.14.0a0 (heads/main:a895756aec, May 10 2024, 16:56:55) [GCC 10.2.1 20210110] on linux
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']

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bug
    on May 10, 2024
  2. added
    topic-repl
    3.13
    3.14
    on May 10, 2024
  3. added a commit that references this issue on Jun 11, 2024
  4. added a commit that references this issue on Jun 11, 2024
  5. added a commit that references this issue on Jun 11, 2024
  6. added a commit that references this issue on Jun 11, 2024
  7. encukou commented on Jun 12, 2024

    @encukou
    Member
  8. added a commit that references this issue on Jun 12, 2024
  9. added a commit that references this issue on Jun 12, 2024
  10. added a commit that references this issue on Jun 12, 2024
  11. pablogsal commented on Jun 12, 2024

    @pablogsal
    Member

    It seems that this change broke a buildbot, see: https://buildbot.python.org/all/#/builders/249/builds/8895/steps/5/logs/stdio

    It looks like a timeout.... I will try to investigate today

  12. 8 remaining items

  13. added 3 commits that reference this issue on Jun 26, 2024
  14. added a commit that references this issue on Jun 26, 2024
  15. added a commit that references this issue on Jun 26, 2024
  16. added 4 commits that reference this issue on Jun 30, 2024
  17. added 4 commits that reference this issue on Jul 17, 2024
  18. maurycy commented on Dec 6, 2026

    @maurycy
    Contributor

    Fixed in d611c4c (3.13; #121054), the REPL uses the __main__ namespace now:

    def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
    if not CAN_USE_PYREPL:
    if not os.getenv('PYTHON_BASIC_REPL') and FAIL_REASON:
    from .trace import trace
    trace(FAIL_REASON)
    print(FAIL_REASON, file=sys.stderr)
    return sys._baserepl()
    if not mainmodule:
    mainmodule = types.ModuleType("__main__")
    namespace = mainmodule.__dict__
    # sys._baserepl() above does this internally, we do it here
    startup_path = os.getenv("PYTHONSTARTUP")
    if pythonstartup and startup_path:

    cc @StanFromIreland

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.133.14topic-repltype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions