← 返回首页
gh-119102: Fix REPL for dumb terminal by vstinner · Pull Request #119269 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-119102: Fix REPL for dumb terminal#119269

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:pyrepl_dumb
May 21, 2024
Merged

gh-119102: Fix REPL for dumb terminal#119269
vstinner merged 1 commit into
python:mainfrom
vstinner:pyrepl_dumb

Conversation

vstinner commented May 20, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Move CAN_USE_PYREPL variable from _pyrepl.main to _pyrepl and rename it to _CAN_USE_PYREPL. Use the variable in the site module to decide if _pyrepl.write_history_file() can be used.

Copy link
Copy Markdown
Member Author

cc @pablogamboa @ambv

Comment thread Lib/site.py Outdated
import _pyrepl
try:
if os.getenv("PYTHON_BASIC_REPL"):
if os.getenv("PYTHON_BASIC_REPL") or not _pyrepl._CAN_USE_PYREPL:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

question: This is working, I presume, because we're hitting the except block in __main__ when we have a dumb TERM setting? I was initially a bit confused because I wasn't seeing why an extra conditional on a setting for a win32 check would fix this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

_pyrepl._CAN_USE_PYREPL is set to False if pyrepl fails at startup.

Copy link
Copy Markdown
Member Author

@ambv: Do you have an idea on how to fix mypy?

eugenetriguba commented May 21, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

@vstinner Using from . import _CAN_USE_PYREPL instead of import _pyrepl seems to work. Not sure if there is a better solution It seems to work in that it makes mypy happy, but it wouldn't allow updating the variable in the other module 🙂

Copy link
Copy Markdown
Member Author

@vstinner Using from . import _CAN_USE_PYREPL instead of import _pyrepl seems to work.

In that case, _CAN_USE_PYREPL = False only sets the variable in __main__.py, not in __init__.py.

Use CAN_USE_PYREPL of _pyrepl.__main__ in the site module to decide if _pyrepl.write_history_file() can be used.

Copy link
Copy Markdown
Member Author

I rewrote the fix to please the typing gods.

vstinner merged commit 73f4a58 into python:main May 21, 2024
vstinner deleted the pyrepl_dumb branch May 21, 2024 12:53
vstinner added the needs backport to 3.13 bugs and security fixes label May 21, 2024

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. 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 May 21, 2024
Use CAN_USE_PYREPL of _pyrepl.__main__ in the site module to decide if _pyrepl.write_history_file() can be used. (cherry picked from commit 73f4a58) Co-authored-by: Victor Stinner <vstinner@python.org>

bedevere-app Bot commented May 21, 2024

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label May 21, 2024
vstinner added a commit that referenced this pull request May 21, 2024
gh-119102: Fix REPL for dumb terminal (GH-119269) Use CAN_USE_PYREPL of _pyrepl.__main__ in the site module to decide if _pyrepl.write_history_file() can be used. (cherry picked from commit 73f4a58) Co-authored-by: Victor Stinner <vstinner@python.org>

Copy link
Copy Markdown
Contributor

I rewrote the fix to please the typing gods.

@vstinner the new version doesn't seem to fix the issue for me (tested on Fedora 39).

I've ran into the same problem when I was trying to fix this. It looks like from _pyrepl.__main__ import CAN_USE_PYREPL re-executes the code in __main__, and therefore CAN_USE_PYREPL will always be True on non-windows systems.

Copy link
Copy Markdown
Member

Same behavior for me that @danielhollas described.

Copy link
Copy Markdown
Member Author

Sorry, I didn't retest functionally after fixing mypy 😬

Copy link
Copy Markdown
Member Author

Please check my second fix: PR gh-119332.

ambv added the topic-repl Related to the interactive shell label May 23, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Use CAN_USE_PYREPL of _pyrepl.__main__ in the site module to decide if _pyrepl.write_history_file() can be used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news topic-repl Related to the interactive shell

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Footer

© 2026 GitHub, Inc.