8000 gh-122273: Support PyREPL history in Windows by devdanzin · Pull Request #122274 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-122273: Support PyREPL history in Windows #122274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only import _pyrepl if PYTHON_BASIC_REPL isn't set.
  • Loading branch information
devdanzin committed Oct 12, 2024
commit 9ad8e721373bf7b53d2fb9141fd3fc4863a80e3d
16 changes: 10 additions & 6 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,13 @@ def register_readline():
import readline
real_readline = True
except ImportError:
import _pyrepl.readline as readline
readline = None
real_readline = False
import rlcompleter # noqa: F401
if PYTHON_BASIC_REPL:
CAN_USE_PYREPL = False
else:
import _pyrepl.readline as readline
from _pyrepl.main import CAN_USE_PYREPL
if real_readline:
import _pyrepl.unix_console
Expand All @@ -521,9 +522,10 @@ def register_readline():

# Reading the initialization (config) file may not be enough to set a
# completion key, so we set one first and then read the file.
if getattr(readline, "backend", None) == 'editline':
backend = getattr(readline, "backend", None)
if backend == 'editline':
readline.parse_and_bind('bind ^I rl_complete')
else:
elif backend:
readline.parse_and_bind('tab: complete')

try:
Expand All @@ -536,7 +538,7 @@ def register_readline():
# want to ignore the exception.
pass

if readline.get_current_history_length() == 0:
if readline and readline.get_current_history_length() == 0:
# If no history was loaded, default to .python_history,
# or PYTHON_HISTORY.
# The guard is necessary to avoid doubling history size at
Expand All @@ -553,13 +555,15 @@ def register_readline():
exceptions = OSError

try:
readline_module.read_history_file(history)
if readline:
readline_module.read_history_file(history)
except exceptions:
pass

def write_history():
try:
readline_module.write_history_file(history)
if readline:
readline_module.write_history_file(history)
except (FileNotFoundError, PermissionError):
# home directory does not exist or is not writable
# https://bugs.python.org/issue19891
Expand Down
0