Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions Lib/test/test_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ def my_hook():
readline.set_pre_input_hook(my_hook)
self.assertIs(readline.get_pre_input_hook(), my_hook)

def test_environment_is_not_modified(self):
# os.environ contains enviroment at the time "os" module was loaded, so
# before the "readline" module is loaded.
original_env = dict(os.environ)

# Force refresh of os.environ and make sure it is the same as before the
# refresh.
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent :mod:`readline` from overriding the ``COLUMNS`` and ``LINES``
environment variables, as values are not updated on terminal resize.
7 changes: 7 additions & 0 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,13 @@ setup_readline(readlinestate *mod_state)
/* The name must be defined before initialization */
rl_readline_name = "python";

#if !defined(__APPLE__)
Copy link
Author

Choose a reason for hiding this comment

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

I'm a bit surprised I had to rely on the __APPLE__ define here. As I understand apple OS is using libedit, so I would have thought relying on WITH_EDITLINE would be enough. But the macOS pipeline proved me wrong...

/* 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
*/
Expand Down
Loading