Skip to content

Use new REPL for the "code" module #119512

Description

@treyhunner

Feature or enhancement

Proposal:

When installing Django in a Python 3.13 virtual environment and using Django's shell command, the old REPL is used.

It would be great if the code module supported the new REPL. From @ambv's reply in #119433 (comment) it looks like this will be considered in Python 3.14.


I would also like to know what projects should do in the meantime. For example, I found a way to modify Django's shell command in one's own project to use the new REPL, by using this within a try-except block:

from _pyrepl.simple_interact import run_multiline_interactive_console
run_multiline_interactive_console()

Is this an acceptable workaround before Python 3.14 is released? Or should this function not be relied on, seeing as it's in an undocumented module?

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

#119433 (review)

Linked PRs

Activity

  1. ambv commented on May 24, 2024

    @ambv
    Contributor

    Is this an acceptable workaround before Python 3.14 is released?

    It's unsupported as the underscore in the module name suggests. External projects will do as they please.

  2. brenns10 commented on Oct 16, 2024

    @brenns10

    Hello, I work on drgn which is a debugger implemented as a Python library. One of the modes drgn has is to launch a Python REPL using the code module, with several variables and modules pre-imported.

    We'd definitely love to see a supported way to use the improved REPL for the code module, so a big 👍 from us on this suggestion. The multiline editing is really exciting and a major usability enhancement, so thanks for all the work on that.

    I did want to share a couple potential issues with using the pyrepl with the code module. Drgn has a few customizations to its REPL:

    1. Using a custom history file, since the code you typically write in a drgn shell in very different from what you'd write in a normal Python shell.
    2. A custom tab-completer which is like that provided by rlcompleter, but also supports completions on objects that are indexed by a string or number (e.g. object["foo"].<TAB> would provide a completion, whereas rlcompleter does not).
    3. A custom displayhook to render certain objects more like a debugger would.

    In fact, the readline module documentation even has an example of configuring code.InteractiveInterpreter in a similar way (see the last code snippet at the bottom of the page).

    If the code module switches to using _pyrepl, even optionally, then it would be really great to have a way to adjust the history file and completion options that are used. Is that something which would be in scope for this request?

  3. ambv commented on Oct 16, 2024

    @ambv
    Contributor

    We'll look into making code.py optionally use PyREPL in 3.14. It will require some code to be moved around as currently PyREPL actually depends on code.py.

  4. skirpichev commented on Apr 11, 2025

    @skirpichev
    Member

    Ok, I'll try to address this issue: I depend on the code module to implement a customized repl for several projects (diofant, mpmath). I hope it's not too late for 3.14.

  5. self-assigned this
    on Apr 11, 2025
  6. removed their assignment
    on May 5, 2025
  7. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 2, 2025
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

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions