Skip to content
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

Python 3.13.0b3 REPL empties ~/.python_history #121245

Open
hroncok opened this issue Jul 1, 2024 · 8 comments
Open

Python 3.13.0b3 REPL empties ~/.python_history #121245

hroncok opened this issue Jul 1, 2024 · 8 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@hroncok
Copy link
Contributor

hroncok commented Jul 1, 2024

Bug report

Bug description:

As discussed in https://discuss.python.org/t/python-3-13-0-beta-3-now-available/56847/7 and #120766 (comment)

When I updated from Python 3.13.0b2 to b3 and started the REPL for the first time, pressing arrow up showed the history.

Upon exiting and starting again, there is no more history when I press arrow up. I noticed it is also missing from my other Python REPLs. ~/.python_history is empty.

To reproduce, I did:

  1. run python3.13
  2. press arrow up, hit enter
  3. Ctrl+D
  4. run python3.13 again -- no history

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

@hroncok hroncok added the type-bug An unexpected behavior, bug, or error label Jul 1, 2024
@hroncok
Copy link
Contributor Author

hroncok commented Jul 1, 2024

This is always reproducible:

$ python3.12
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 13.2.1 20240316 (Red Hat 13.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 'Save this'
'Save this'
>>> ^D

$ cat ~/.python_history 
'Save this'

$ python3.13
Python 3.13.0b3 (main, Jun 28 2024, 00:00:00) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> [arrow up]'Save this'
'Save this'
>>> ^D

$ cat ~/.python_history 
(empty)

$ python3.12
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 13.2.1 20240316 (Red Hat 13.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> [arrow up]
(empty)
@hugovk hugovk added topic-repl Related to the interactive shell 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jul 1, 2024
@hroncok
Copy link
Contributor Author

hroncok commented Jul 1, 2024

@domdfcoding wrote:

... The first time Python 3.13 runs the history is there, but after exiting and running again the history has gone. Running an older Python populates the history with new entries but they're lost the next time Python 3.13 exits.

Git bisect tracked the issue to 38cfa92. The actual issue is in site.py, where it tries to import CAN_USE_PYREPL from __main__, which it's no longer located in as of that commit.

cpython/Lib/site.py

Lines 527 to 532 in c7991cc

def write_history():
try:
# _pyrepl.__main__ is executed as the __main__ module
from __main__ import CAN_USE_PYREPL
except ImportError:
CAN_USE_PYREPL = False

Changing this to from _pyrepl.main import CAN_USE_PYREPL or adding from .main import CAN_USE_PYREPL to the top of _pyrepl.__main__.py seems to fix it. (I couldn't make it work reliably at first but I think that was me forgetting that site.py is frozen)

@hroncok
Copy link
Contributor Author

hroncok commented Jul 1, 2024

Moreover, I believe that even if the code in site.py "cannot use pyrepl", it should never ever write empty history.

skirpichev added a commit to skirpichev/cpython that referenced this issue Jul 2, 2024
This prevents writing incorrect history (empty).
@skirpichev
Copy link
Contributor

PR is ready: #121255

@hroncok
Copy link
Contributor Author

hroncok commented Jul 2, 2024

Suggestion: Let's merge #121255 as is but do not close this issue yet. I think there are multiple improvements possible:

@skirpichev
Copy link
Contributor

Yep, I'll work on this in second pr.

hroncok added a commit to fedora-python/cpython that referenced this issue Jul 2, 2024
This prevents writing incorrect history (empty).

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
ambv pushed a commit that referenced this issue Jul 2, 2024
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
hroncok added a commit to fedora-python/cpython that referenced this issue Jul 2, 2024
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
skirpichev added a commit to skirpichev/cpython that referenced this issue Jul 2, 2024
* make readline stuff more symmetrical wrt reading/writing
* prevent truncation of the history file
* add regression test

Should finally address python#121245.
skirpichev added a commit to skirpichev/cpython that referenced this issue Jul 2, 2024
* make readline stuff more symmetrical wrt reading/writing
* prevent truncation of the history file
* add regression test

Should finally address python#121245.
@skirpichev
Copy link
Contributor

Second PR is ready for review: #121259

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 2, 2024
(cherry picked from commit 7a807c3)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
lysnikolaou pushed a commit that referenced this issue Jul 2, 2024
(cherry picked from commit 7a807c3)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Akasurde pushed a commit to Akasurde/cpython that referenced this issue Jul 3, 2024
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 3, 2024
…onGH-121259)

(cherry picked from commit afee76b)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@hroncok hroncok closed this as completed Jul 4, 2024
@skirpichev
Copy link
Contributor

See #121351. @hroncok, I think that means that simple patch from the first PR doesn't fix problem on all systems.

Probably we should use my patch 8195067 from #121259. To make it work we can set CAN_USE_REPL before loading the site module, see #121259 (comment)

skirpichev added a commit to skirpichev/cpython that referenced this issue Jul 6, 2024
@hroncok hroncok reopened this Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
3 participants