Repository navigation
python -m asyncio does not respect PYTHON_BASIC_REPL=1 #140002
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 12, 2025 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Oct 12, 2025 The fix here would probably have to consist of having 2 separate asyncio REPL implementations, since
InteractiveColoredConsolealready inherits fromcode.InteracticeConsole, and over time, a few pyrepl-specific changes have been introduced toAsyncIOInteractiveConsole.Sounds like a split would add a bit of maintenance burden for the future. Maybe it could also be considered to explicitly only support pyrepl with
asyncio -m?Would probably still have to fix this for the current version, as it's not really working "as advertised".
Would probably still have to fix this for the current version, as it's not really working "as advertised".
Is it though? The asyncio repl docs (a few sections down, direct linking is not possible) do not mention it respecting
PYTHON_BASIC_REPL?Would probably still have to fix this for the current version, as it's not really working "as advertised".
Is it though? The asyncio repl docs (a few sections down, direct linking is not possible) do not mention it respecting
PYTHON_BASIC_REPL?Well it was deliberately introduced in #119433, which also includes in its description:
support
PYTHON_BASIC_REPLso whether documented or not, it was definitely intended to work, and it does do something, it just doesn't properly fall back to the regular REPL.
I don't think there is any problem with how
PYTHON_BASIC_REPLenvironment variable is handled, but there are problems regarding the code paths that asyncio REPL hits. The current asyncio REPL does hit code paths of something that is reserved for the new REPL only.Namely, it does not handle multi-line input properly, because it runs
runsource()ofInteractiveColoredConsole.runsource()which was only meant to be called from_pyrepl.simple_interact.run_multiline_interactive_consolethat handles multi-line input using its own logic (tracked in #140013).Other than that, is there anything else that manifests improper fallback?
What are the exact behaviors that don't align with what you are expecting?(Of course ignoring all differences stemming from not calling
sys._baserepl(), because the asyncio REPL has to intercept inputs and produce coroutine functions from them on the fly using a Python wrapper, at least as long the basic REPL fallback is implemented in Python).Other than that, is there anything else that manifests improper fallback?
What are the exact behaviors that don't align with what you are expecting?Please describe some specifics so we can set up issues to track. I'm filing the one for multi-line input handling.
I don't think there is any problem with how
PYTHON_BASIC_REPLenvironment variable is handled, but there are problems regarding the code paths that asyncio REPL hits. The current asyncio REPL does hit code paths of something that is reserved for the new REPL only.Just to be clear: You are saying that it is not generally a problem that setting
PYTHON_BASIC_REPL=1does not use the basic repl?If so, that is at least somewhat unexpected, and, judging from the tests and code, it does not appear to be the intended behaviour.
For example, looking at_pyrepl.main.interactive_console:Lines 25 to 31 in 1bfe86c
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() we can see that it falls back to
sys._baserepl, and not into a "baserepl-like mode of pyrepl".If this discrepancy in behaviour is considered to not be an issue though that's fine with me, as I do not know the intentions behind this divergence and there doesn't seem to be anything obviously wrong with the behaviour.
What are the exact behaviors that don't align with what you are expecting?
I haven't observed any discrepancies, other than a test case failing unsuspectedly when working on the asyncio repl. I tried to adapt this one for an asyncio repl test and found that it fails due to the behaviour mentioned above.
Are there any user-facing issues with the asyncio REPL when
PYTHON_BASIC_REPL=1is set?That test assertion is violated by
python -m asynciobecause the asyncio REPL must import_pyreplto build its own compile-and-run loop that supports top-levelawait. Consequently, because it supports top-levelawaits, it can't fall back tosys._baserepl(sys._baserepldoesn't implement an "asyncio mode"). The failure is therefore expected and has no user-visible consequence -- it's not a bug in the asyncio REPL.Are there any user-facing issues with the asyncio REPL when
PYTHON_BASIC_REPL=1is set?As I explained in my comment above, none that I am aware of, other than the fact that it's unexpected behaviour.
That test assertion is violated by
python -m asynciobecause the asyncio REPL must import_pyreplto build its own compile-and-run loop that supports top-levelawait. Consequently, because it supports top-levelawaits, it can't fall back tosys._baserepl(sys._baserepldoesn't implement an "asyncio mode")I'm not sure I understand the part about the asyncio REPL depending on
_pyrepl. Maybe I'm missing something here?The asyncio REPL was introduced before
_pyrepl. Before #119433 it did not use_pyrepl, and from my understanding, there's nothing the asyncio REPL does that inherently requires functionality exclusively available via_pyrepl.Can you explain what functionality of
_pyrepl(specificallyInteractiveColoredConsole) the asyncio REPL needs to support top-level await, that is not provided bycode.InteractiveConsole, which it used before the introduction of_pyrepl?CC @ambv
Filed #140570 where we explicitly recommend using the new REPL mode instead.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
When using
python -m asyncio, the REPL does not respectPYTHON_BASIC_REPL=1.Using a test case from the pyrepl test suite, we can clearly see pyrepl is being used:
cpython/Lib/test/test_pyrepl/test_pyrepl.py
Lines 1593 to 1597 in 6710156
Looking at the source of
asyncio.__main__, this makes perfect sense, as the asyncio REPL is a customised version of_pyrepl.console.InteractiveColoredConsole:cpython/Lib/asyncio/__main__.py
Lines 16 to 21 in 6710156
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux