Skip to content

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Sep 27, 2025

The issue with the tests is that those that don't specify an environment actually use -I and the current environment. Even if the latter is modified with a different PYTHON_HISTORY, because of -I, it will be ignored by gethistoryfile().

I decided that it was cleaner to assume that None environment means "use a copy of the current one" and that the it shouldn't be possible to specify -I at the same time if we internally add PYTHON_HISTORY ourselves.

I believe that we need a better mechanism, but for now, I want to prevent the test suite to overwrite ~/.python_history (this could be especially annoying for those who actually want to install python system-wide; alternatively, we could make sure to restore the history file at the end of the test).

@picnixz
Copy link
Member Author

picnixz commented Sep 27, 2025

NVM, there are other places that alter this file.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

It might be worth modifying regrtest to check if the Python history file changed.

@picnixz
Copy link
Member Author

picnixz commented Sep 27, 2025

Yeah, I'll do that tomorrow to catch the possible issues. I can also make it part of the "ENV CHANGED" check

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

Urgh, regrtest is awfully hard to change because it's spanned across multiple files and the structure is not documented well. I'm going to locally check that we don't change anything, but otherwise I won't change this in this PR.

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

If possible, I'd like to suggest a cleaner way to implement regrtest, or at least properly document the interfaces (I'm not even sure that my check is actually checked so for now I just added a plain assert False to make the tests early abort).

EDIT: for now, all regular tests pass and don't modify the history.

@yihong0618
Copy link
Contributor

This work but will print a lot of messages is that expected?

FAIL: test_zipfile (test.test_cmd_line_script.CmdLineTest.test_zipfile)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 368, in tearDown
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 28) != (32768, 13)

First differing element 1:
28
13

- (32768, 28)
?         ^^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_zipfile_compiled_checked_hash (test.test_cmd_line_script.CmdLineTest.test_zipfile_compiled_checked_hash)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 368, in tearDown
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 28) != (32768, 13)

First differing element 1:
28
13

- (32768, 28)
?         ^^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_zipfile_compiled_timestamp (test.test_cmd_line_script.CmdLineTest.test_zipfile_compiled_timestamp)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 368, in tearDown
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 28) != (32768, 13)

First differing element 1:
28
13

- (32768, 28)
?         ^^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_zipfile_compiled_unchecked_hash (test.test_cmd_line_script.CmdLineTest.test_zipfile_compiled_unchecked_hash)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 368, in tearDown
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 28) != (32768, 13)

First differing element 1:
28
13

- (32768, 28)
?         ^^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_zipfile_error (test.test_cmd_line_script.CmdLineTest.test_zipfile_error)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 368, in tearDown
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 28) != (32768, 13)

First differing element 1:
28
13

- (32768, 28)
?         ^^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 28, 2025

update...seems not work on mac
my history gone...


firsttime make test I already have some history but print the message and history gone
secondtime make test no history right
thirdtime make test have some history no error message but hiostory also gone.

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

Well, I don't have a Mac for testing zipfile. I don't have an issue on Linux with zipfile though (I actually had NO issue about wiping the history file, only about the history being altered so I don't really understand. Which test is actually removing the history file? all "errors" are only about the file being altered, not being deleted)

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 28, 2025

Well, I don't have a Mac for testing zipfile. I don't have an issue on Linux with zipfile though (I actually had NO issue about wiping the history file, only about the history being altered so I don't really understand. Which test is actually removing the history file? all "errors" are only about the file being altered, not being deleted)

not sure...will help to check it on mac later.

on branch fix/repl/history-alteration-139352
commit 41ceb15
before the make test

➜ cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
1
2

after the make test

cat ~/.python_history # nothing

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

Ok wait a moment.

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

Can you recheck what happens for you if run make test here and ./python -m test -j12 (both)?

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 28, 2025

Can you recheck what happens for you if run make test here and ./python -m test -j12 (both)?

doing

git pull

make test (not all if you need will paste all)

FAIL: test_repl_stderr_flush (test.test_cmd_line_script.CmdLineTest.test_repl_stderr_flush)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_repl_stderr_flush_separate_stderr (test.test_cmd_line_script.CmdLineTest.test_repl_stderr_flush_separate_stderr)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_repl_stdout_flush (test.test_cmd_line_script.CmdLineTest.test_repl_stdout_flush)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_repl_stdout_flush_separate_stderr (test.test_cmd_line_script.CmdLineTest.test_repl_stdout_flush_separate_stderr)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_script_abspath (test.test_cmd_line_script.CmdLineTest.test_script_abspath)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_script_as_dev_fd (test.test_cmd_line_script.CmdLineTest.test_script_as_dev_fd)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_script_compiled (test.test_cmd_line_script.CmdLineTest.test_script_compiled)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_source_lines_are_shown_when_running_source (test.test_cmd_line_script.CmdLineTest.test_source_lines_are_shown_when_running_source)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_stdin_loader (test.test_cmd_line_script.CmdLineTest.test_stdin_loader)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_syntaxerror_does_not_crash (test.test_cmd_line_script.CmdLineTest.test_syntaxerror_does_not_crash)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_syntaxerror_indented_caret_position (test.test_cmd_line_script.CmdLineTest.test_syntaxerror_indented_caret_position)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 8) != (32768, 13)

First differing element 1:
8
13

- (32768, 8)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/hyi/.python_history') was altered

======================================================================
FAIL: test_syntaxerror_invalid_escape_sequence_multi_line (test.test_cmd_line_script.CmdLineTest.test_syntaxerror_invalid_escape_sequence_multi_line)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/prs/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

FTR, I've tested both make test and python -m test -j12 and nothing happened so I don't know why it fails on macOS. The tests seem the same. But maybe there is a tearDown() somewhere that wipes out ~/.python_history.

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 28, 2025

after make test

➜ cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
HiStOrY_V2
➜ cpython git:(fix/repl/history-alteration-139352)


./python.exe -m test -j12 is on going

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

make test (not all if you need will paste all)

I need to know which test actually removed the history. Is the history file empty after the tests, or is it just gone (that is ls ~/.python_history fails)

@yihong0618
Copy link
Contributor

j12 is the same...
➜ cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
HiStOrY_V2

@yihong0618
Copy link
Contributor

make test (not all if you need will paste all)

I need to know which test actually removed the history. Is the history file empty after the tests, or is it just gone (that is ls ~/.python_history fails)

yes help checking now

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 28, 2025

@picnixz this guy

➜ cpython git:(fix/repl/history-alteration-139352) ./python.exe
Python 3.15.0a0 (heads/fix/repl/history-alteration-139352:e44596e975, Sep 28 2025, 17:58:41) [Clang 17.0.0 (clang-1700.0.13.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

1
1
2
2

➜ cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
1
2
➜ cpython git:(fix/repl/history-alteration-139352) ./python.exe -m unittest test.test_cmd_line
s.........s..s........s...............ss..ss.s.............................

Ran 75 tests in 1.960s

OK (skipped=9)
➜ cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
HiStOrY_V2

and not sure if there others

test_future_stmt also


and its not gone its shows _HiStOrY_V2_

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

Huh, so actually what might happen is that we're trying to write to the history file but the latter is somehow overwritten in a bad manner. I may think of one reason, that is:

def read_history_file(self, filename: str = gethistoryfile()) -> None: ...
def write_history_file(self, filename: str = gethistoryfile()) -> None: ...
def append_history_file(self, filename: str = gethistoryfile()) -> None: ...

Those functions in _pyrepl.readline are actually using a possibly already-cached history file. So that may be the issue. Can you do first apply the following patch:

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index 23b8fa6b9c7..471a955e3a4 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -431,6 +431,7 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
         # history item: we use \r\n instead of just \n.  If the history
         # file is passed to GNU readline, the extra \r are just ignored.
         history = self.get_reader().history
+        print("history = ", filename, "\n", history)

         with open(os.path.expanduser(filename), 'rb') as f:
             is_editline = f.readline().startswith(b"_HiStOrY_V2_")
@@ -457,6 +458,7 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
     def write_history_file(self, filename: str = gethistoryfile()) -> None:
         maxlength = self.saved_history_length
         history = self.get_reader().get_trimmed_history(maxlength)
+        print("history = ", filename, "\n", history)
         f = open(os.path.expanduser(filename), "w",
                  encoding="utf-8", newline="\n")
         with f:
@@ -469,6 +471,7 @@ def append_history_file(self, filename: str = gethistoryfile()) -> None:
         saved_length = self.get_history_length()
         length = self.get_current_history_length() - saved_length
         history = reader.get_trimmed_history(length)
+        print("history = ", filename, "\n", history)
         f = open(os.path.expanduser(filename), "a",
                  encoding="utf-8", newline="\n")
         with f:

To apply the patch, first write in your console:

cat <<-EOM > repl.patch

then, copy-paste the following:

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index 23b8fa6b9c7..471a955e3a4 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -431,6 +431,7 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
         # history item: we use \r\n instead of just \n.  If the history
         # file is passed to GNU readline, the extra \r are just ignored.
         history = self.get_reader().history
+        print("history = ", filename, "\n", history)

         with open(os.path.expanduser(filename), 'rb') as f:
             is_editline = f.readline().startswith(b"_HiStOrY_V2_")
@@ -457,6 +458,7 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
     def write_history_file(self, filename: str = gethistoryfile()) -> None:
         maxlength = self.saved_history_length
         history = self.get_reader().get_trimmed_history(maxlength)
+        print("history = ", filename, "\n", history)
         f = open(os.path.expanduser(filename), "w",
                  encoding="utf-8", newline="\n")
         with f:
@@ -469,6 +471,7 @@ def append_history_file(self, filename: str = gethistoryfile()) -> None:
         saved_length = self.get_history_length()
         length = self.get_current_history_length() - saved_length
         history = reader.get_trimmed_history(length)
+        print("history = ", filename, "\n", history)
         f = open(os.path.expanduser(filename), "a",
                  encoding="utf-8", newline="\n")
         with f:
EOM

You should have a file named repl.patch that contains the above patch. Then apply the patch:

$ git apply repl.patch

Now, run the following commands:

$ echo "1\n2\n3\n" > ~/.python_history
$ cat ~/.python_history
$ ./python -m test test_cmd_line_script -m test_repl_stderr_flush -v
$ cat ~/.python_history

and paste the entire output here.

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 28, 2025

cat ~/.python_history

➜  cpython git:(fix/repl/history-alteration-139352) ✗ echo "1\n2\n3\n" > ~/.python_history
➜  cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
1
2
3
➜  cpython git:(fix/repl/history-alteration-139352) ✗  ./python.exe -m test test_cmd_line_script -m test_repl_stderr_flush -v
== CPython 3.15.0a0 (heads/hy/color_the_timeit_traceback-dirty:f798c4ed1c, Sep 27 2025, 16:59:31) [Clang 17.0.0 (clang-1700.0.13.5)]
== macOS-15.3.2-arm64-arm-64bit-Mach-O little-endian
== Python build: release
== cwd: /Users/yihong/repos/cpython/build/test_python_worker_91202æ
== CPU count: 10
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 3482497145
0:00:00 load avg: 4.03 Run 1 test sequentially in a single process
0:00:00 load avg: 4.03 [1/1] test_cmd_line_script
test_repl_stderr_flush (test.test_cmd_line_script.CmdLineTest.test_repl_stderr_flush) ... FAIL

======================================================================
FAIL: test_repl_stderr_flush (test.test_cmd_line_script.CmdLineTest.test_repl_stderr_flush)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/yihong/repos/cpython/Lib/test/support/script_helper.py", line 387, in tearDown
    self.__history_teardown_check()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/yihong/repos/cpython/Lib/test/support/script_helper.py", line 374, in __history_teardown_check
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.__history_stat,
        ^^^^^^^^^^^^^^^^^^^^
        _file_signature(self.__history_file),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        f"PYTHON_HISTORY file ({self.__history_file!r}) was altered"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: Tuples differ: (32768, 7) != (32768, 13)

First differing element 1:
7
13

- (32768, 7)
?         ^

+ (32768, 13)
?         ^^
 : PYTHON_HISTORY file ('/Users/yihong/.python_history') was altered

----------------------------------------------------------------------
Ran 1 test in 0.050s

FAILED (failures=1)
test test_cmd_line_script failed
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/yihong/repos/cpython/Lib/test/__main__.py", line 2, in <module>
    main(_add_python_opts=True)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yihong/repos/cpython/Lib/test/libregrtest/main.py", line 794, in main
    Regrtest(ns, _add_python_opts=_add_python_opts).main(tests=tests)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/yihong/repos/cpython/Lib/test/libregrtest/main.py", line 786, in main
    exitcode = self.run_tests(selected, tests)
  File "/Users/yihong/repos/cpython/Lib/test/libregrtest/main.py", line 617, in run_tests
    return self._run_tests(selected, tests)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/yihong/repos/cpython/Lib/test/libregrtest/main.py", line 582, in _run_tests
    self.run_tests_sequentially(runtests)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/yihong/repos/cpython/Lib/test/libregrtest/main.py", line 442, in run_tests_sequentially
    result = self.run_test(test_name, runtests, tracer)
  File "/Users/yihong/repos/cpython/Lib/test/libregrtest/main.py", line 412, in run_test
    raise AssertionError(f"{test_name}: altered history file")
AssertionError: test_cmd_line_script: altered history file
``
➜  cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
_HiStOrY_V2_

@yihong0618
Copy link
Contributor

is there somehing else I can help here?

@picnixz
Copy link
Member Author

picnixz commented Sep 28, 2025

I think there is something with macOS and editline that is different than on Linux. I don't have this _HiStOrY_V2_ additional line and I don't know from where it comes from. There is no occurrence of Python adding it (it's only "reading"). Can you indeed check that git grep "_HiStOrY_V2_" returns only

Lib/_pyrepl/readline.py:            is_editline = f.readline().startswith(b"_HiStOrY_V2_")

What might happen however is that interactive_python is somehow polluting the history and doesn't use the hook I defined. As I can't test this, I will need someone on a macOS to help digging this issue themselves.

cc @ambv @pablogsal

@yihong0618
Copy link
Contributor

git grep "_HiStOrY_V2_"

git grep "HiStOrY_V2"

Lib/_pyrepl/readline.py: is_editline = f.readline().startswith(b"HiStOrY_V2")

@yihong0618
Copy link
Contributor

linux for this patch works well

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 29, 2025

@picnixz @ZeroIntensity

a bit dig users especialy for mac users the deafault readline maybe editline..

when use editline the clean history happens

  cpython git:(fix/repl/history-alteration-139352) ./python.exe -c "import readline; print(hasattr(readline, 'backend')); import sys; print(sys.platform)"
True
darwin
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe -c "import readline; print(readline.backend if hasattr(readline, 'backend') else 'No backend')"
editline
➜  cpython git:(fix/repl/history-alteration-139352) head -5 ~/.python_history
_HiStOrY_V2_
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe -c "import readline; print('Backend:', readline.backend); print('History length:', readline.get_current_history_length())"
Backend: editline
History length: 0
➜  cpython git:(fix/repl/history-alteration-139352) cp ~/.python_history ~/.python_history.backup
➜  cpython git:(fix/repl/history-alteration-139352) ✗ echo -e "_HiStOrY_V2_\n12\n2" > ~/.python_history
➜  cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
_HiStOrY_V2_
12
2
➜  cpython git:(fix/repl/history-alteration-139352) ✗ ./python.exe -m unittest test.test_cmd_line
s.........s..s........s...............ss..ss.s.............................
----------------------------------------------------------------------
Ran 75 tests in 1.995s

OK (skipped=9)
➜  cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
_HiStOrY_V2_
12
2

the quite fix diff(maybe others)

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index 23b8fa6b9c..1ac1f88b02 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -457,9 +457,21 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
     def write_history_file(self, filename: str = gethistoryfile()) -> None:
         maxlength = self.saved_history_length
         history = self.get_reader().get_trimmed_history(maxlength)
-        f = open(os.path.expanduser(filename), "w",
-                 encoding="utf-8", newline="\n")
+        filename_expanded = os.path.expanduser(filename)
+        # Simple check: if existing file starts with _HiStOrY_V2_, preserve editline format
+        use_editline_format = False
+        try:
+            with open(filename_expanded, 'rb') as f:
+                if f.readline().startswith(b"_HiStOrY_V2_"):
+                    use_editline_format = True
+        except (FileNotFoundError, PermissionError, OSError):
+            pass
+        
+        f = open(filename_expanded, "w", encoding="utf-8", newline="\n")
         with f:
+            if use_editline_format:
+                # Preserve editline format
+                f.write("_HiStOrY_V2_\n")
             for entry in history:
                 entry = entry.replace("\n", "\r\n")  # multiline history support
                 f.write(entry + "\n")

@yihong0618
Copy link
Contributor

@picnixz @ZeroIntensity

a bit dig users especialy for mac users the deafault readline maybe editline..

when use editline the clean history happens

  cpython git:(fix/repl/history-alteration-139352) ./python.exe -c "import readline; print(hasattr(readline, 'backend')); import sys; print(sys.platform)"
True
darwin
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe -c "import readline; print(readline.backend if hasattr(readline, 'backend') else 'No backend')"
editline
➜  cpython git:(fix/repl/history-alteration-139352) head -5 ~/.python_history
_HiStOrY_V2_
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe -c "import readline; print('Backend:', readline.backend); print('History length:', readline.get_current_history_length())"
Backend: editline
History length: 0
➜  cpython git:(fix/repl/history-alteration-139352) cp ~/.python_history ~/.python_history.backup
➜  cpython git:(fix/repl/history-alteration-139352) ✗ echo -e "_HiStOrY_V2_\n12\n2" > ~/.python_history
➜  cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
_HiStOrY_V2_
12
2
➜  cpython git:(fix/repl/history-alteration-139352) ✗ ./python.exe -m unittest test.test_cmd_line
s.........s..s........s...............ss..ss.s.............................
----------------------------------------------------------------------
Ran 75 tests in 1.995s

OK (skipped=9)
➜  cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
_HiStOrY_V2_
12
2

the quite fix diff(maybe others)

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index 23b8fa6b9c..1ac1f88b02 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -457,9 +457,21 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
     def write_history_file(self, filename: str = gethistoryfile()) -> None:
         maxlength = self.saved_history_length
         history = self.get_reader().get_trimmed_history(maxlength)
-        f = open(os.path.expanduser(filename), "w",
-                 encoding="utf-8", newline="\n")
+        filename_expanded = os.path.expanduser(filename)
+        # Simple check: if existing file starts with _HiStOrY_V2_, preserve editline format
+        use_editline_format = False
+        try:
+            with open(filename_expanded, 'rb') as f:
+                if f.readline().startswith(b"_HiStOrY_V2_"):
+                    use_editline_format = True
+        except (FileNotFoundError, PermissionError, OSError):
+            pass
+        
+        f = open(filename_expanded, "w", encoding="utf-8", newline="\n")
         with f:
+            if use_editline_format:
+                # Preserve editline format
+                f.write("_HiStOrY_V2_\n")
             for entry in history:
                 entry = entry.replace("\n", "\r\n")  # multiline history support
                 f.write(entry + "\n")

this dirty can fix make test on mac

➜ cpython git:(fix/repl/history-alteration-139352) ✗ cat ~/.python_history
HiStOrY_V2
1
2
3

@picnixz
Copy link
Member Author

picnixz commented Sep 29, 2025

@yihong0618 Thanks for the investigation. I included a modified version of the patch. Please try this branch again.

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 29, 2025

@yihong0618 Thanks for the investigation. I included a modified version of the patch. Please try this branch again.

error:

Traceback (most recent call last):
File "", line 575, in register_readline
File "/Users/hyi/prs/cpython/Lib/_pyrepl/readline.py", line 452, in read_history_file
is_editline, encoding = self._analyze_history_file(f)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/Users/hyi/prs/cpython/Lib/_pyrepl/readline.py", line 439, in _analyze_history_file
is_editline = f.readline().startswith(_EDITLINE_BYTES_MARKER)
^
UnboundLocalError: cannot access local variable 'f' where it is not associated with a value

@picnixz
Copy link
Member Author

picnixz commented Sep 29, 2025

Fixed, sorry!

@yihong0618
Copy link
Contributor

yihong0618 commented Sep 29, 2025

Fixed, sorry!

not fully right seems have some format problem

➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
_HiStOrY_V2_
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe
Python 3.15.0a0 (heads/fix/repl/history-alteration-139352-dirty:400e29539d, Sep 29 2025, 18:05:22) [Clang 17.0.0 (clang-1700.0.13.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1
1
>>> 2
2
>>> 
➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
_HiStOrY_V2_\n1\n2\n%      

history broken

@yihong0618
Copy link
Contributor

and I checked my patch is not fully right too

This keep the history only we have _HiStOrY_V2_

if we do not have it

like

➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
1
2

./python.exe -m unittest test.test_cmd_line will clean the history too

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index 23b8fa6b9c..1ac1f88b02 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -457,9 +457,21 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
     def write_history_file(self, filename: str = gethistoryfile()) -> None:
         maxlength = self.saved_history_length
         history = self.get_reader().get_trimmed_history(maxlength)
-        f = open(os.path.expanduser(filename), "w",
-                 encoding="utf-8", newline="\n")
+        filename_expanded = os.path.expanduser(filename)
+        # Simple check: if existing file starts with _HiStOrY_V2_, preserve editline format
+        use_editline_format = False
+        try:
+            with open(filename_expanded, 'rb') as f:
+                if f.readline().startswith(b"_HiStOrY_V2_"):
+                    use_editline_format = True
+        except (FileNotFoundError, PermissionError, OSError):
+            pass
+        
+        f = open(filename_expanded, "w", encoding="utf-8", newline="\n")
         with f:
+            if use_editline_format:
+                # Preserve editline format
+                f.write("_HiStOrY_V2_\n")
             for entry in history:
                 entry = entry.replace("\n", "\r\n")  # multiline history support
                 f.write(entry + "\n")

@picnixz picnixz force-pushed the fix/repl/history-alteration-139352 branch from 400e295 to 1c7e2d9 Compare September 29, 2025 10:23
@picnixz
Copy link
Member Author

picnixz commented Sep 29, 2025

It should be fixed for the format. For the rest idk

@yihong0618
Copy link
Contributor

./python.exe -m unittest test.test_cmd_line

@picnixz works well but same as my patch

This keep the history only we have HiStOrY_V2

if we do not have it

like

➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
1
2
./python.exe -m unittest test.test_cmd_line will clean the history too
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe
Python 3.15.0a0 (heads/hy/color_the_timeit_traceback-dirty:7409fc4f90, Sep 28 2025, 19:16:39) [Clang 17.0.0 (clang-1700.0.13.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1
KeyboardInterrupt
>>> 
➜  cpython git:(fix/repl/history-alteration-139352) 





➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
1
2
import this
➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe -m unittest test.test_cmd_line
s.........s..s........s...............ss..ss.s.............................
----------------------------------------------------------------------
Ran 75 tests in 1.915s

OK (skipped=9)
➜  cpython git:(fix/repl/history-alteration-139352) 





➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
_HiStOrY_V2_
➜  cpython git:(fix/repl/history-alteration-139352) 





➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe
Python 3.15.0a0 (heads/hy/color_the_timeit_traceback-dirty:7409fc4f90, Sep 28 2025, 19:16:39) [Clang 17.0.0 (clang-1700.0.13.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1
1
>>> 2
2
>>> 3
3
>>> 2
KeyboardInterrupt
>>> 
➜  cpython git:(fix/repl/history-alteration-139352) 





➜  cpython git:(fix/repl/history-alteration-139352) ./python.exe -m unittest test.test_cmd_line
s.........s..s........s...............ss..ss.s.............................
----------------------------------------------------------------------
Ran 75 tests in 1.875s

OK (skipped=9)
➜  cpython git:(fix/repl/history-alteration-139352)     





➜  cpython git:(fix/repl/history-alteration-139352) cat ~/.python_history
_HiStOrY_V2_
1
2
3

@yihong0618
Copy link
Contributor

@picnixz dig more....
about the no _HiStOrY_V2_ its a c level issue
it is because with -E its use c level readlne

this patch fix the left issue

diff --git a/Modules/readline.c b/Modules/readline.c
index 630a687999..915f12121e 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -317,6 +317,9 @@ readline_read_history_file_impl(PyObject *module, PyObject *filename_obj)
 
 static int _history_length = -1; /* do not truncate history by default */
 
+/* Forward declaration */
+static int _py_get_history_length_lock_held(void);
+
 /* Exported function to save a readline history file */
 
 /*[clinic input]
@@ -354,6 +357,13 @@ readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
             return NULL;
         }
     }
+    // Check if we have any history to write
+    int current_history_length = _py_get_history_length_lock_held();
+    // If current history is empty, don't overwrite existing file
+    if (current_history_length == 0) {
+        Py_XDECREF(filename_bytes);
+        Py_RETURN_NONE;
+    }
     errno = err = write_history(filename);
     int history_length = FT_ATOMIC_LOAD_INT_RELAXED(_history_length);
     if (!err && history_length >= 0)

with your fix and the diff patch it fix all

and maybe since its two issues here one about editline in mac the other is clean history
is it need to split the patch to two pull request?

@picnixz
Copy link
Member Author

picnixz commented Oct 5, 2025

I never dabbled with the C implementation of readline so I would prefer having someone who is more familiar with it to confirm whether this is the appropriate call. @ambv and @pablogsal: could you perhaps help us here?

Copy link
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

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

I don't have time for this right now, but I don't like this. There's confusion about editline/readline/pyrepl history formats, there's removal of -I that I would like to avoid (if anything, we'd like there to be more -I in tests, not less).


@staticmethod
def _is_editline_history(filename: str | IO[bytes]) -> bool:
if isinstance(filename, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't implement the str bit. Now there's two functions in one.

Comment on lines +474 to +475
if is_editline:
f.write(f"{_EDITLINE_MARKER}\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect and this change is irrelevant to the bug you're fixing. The editline format is somewhat different, a file written by us will not be readable by editline anyway, and now you'll make pyrepl mangle unicode in its own history until you delete the history file.

self.next_single_filename: StrPath | None = None

history_file = os.path.join(os.path.expanduser('~'), '.python_history')
self.__history_file = history_file
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: don't use double underscores. We don't use them anywhere in libregrtest. A single underscore's better.

@bedevere-app
Copy link

bedevere-app bot commented Oct 6, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants