diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py index b9d082b3597f13..6f793939fe298a 100644 --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -405,6 +405,11 @@ def test_write_read_limited_history(self): # So, we've only tested that the read did not fail. # See TestHistoryManipulation for the full test. + def test_environment_is_not_modified(self): + original_env = dict(os.environ) + os.reload_environ() + self.assertEqual(dict(os.environ), original_env) + @unittest.skipUnless(support.Py_GIL_DISABLED, 'these tests can only possibly fail with GIL disabled') class FreeThreadingTest(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-05-07-18-31-31.gh-issue-46927.sF02gj.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-07-18-31-31.gh-issue-46927.sF02gj.rst new file mode 100644 index 00000000000000..3ba9757c8acb5d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-07-18-31-31.gh-issue-46927.sF02gj.rst @@ -0,0 +1,2 @@ +Prevent :mod:`readline` from overriding the ``COLUMNS`` and ``LINES`` +environment variables, as values are not updated on terminal resize. diff --git a/Modules/readline.c b/Modules/readline.c index 0dd99dc66c08e9..f60bdd33b00e2d 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1323,6 +1323,13 @@ setup_readline(readlinestate *mod_state) /* The name must be defined before initialization */ rl_readline_name = "python"; +#if !defined(__APPLE__) + /* Prevent readline from changing environment variables such as LINES and + * COLUMNS. + */ + rl_change_environment = 0; +#endif + /* the libedit readline emulation resets key bindings etc * when calling rl_initialize. So call it upfront */