From b9b59447a154ba6796b18cfb3821cb748b5dfdfb Mon Sep 17 00:00:00 2001 From: kobarity Date: Fri, 6 Mar 2026 16:27:44 +0900 Subject: [PATCH] Improve Python setup codes to avoid leaving global names * lisp/progmodes/python.el (python-shell-setup-code) (python-shell-readline-detect): Improve Python code. (Bug#80551) --- lisp/progmodes/python.el | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 0b4a773516a..ad0e84bf74f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3652,14 +3652,18 @@ eventually provide a shell." (defconst python-shell-setup-code "\ -try: - import termios -except ImportError: - pass -else: - attr = termios.tcgetattr(0) - attr[3] &= ~termios.ECHO - termios.tcsetattr(0, termios.TCSADRAIN, attr)" +def _PYTHON_EL_setup(): + try: + import termios + except ImportError: + pass + else: + attr = termios.tcgetattr(0) + attr[3] &= ~termios.ECHO + termios.tcsetattr(0, termios.TCSADRAIN, attr) + +_PYTHON_EL_setup() +del _PYTHON_EL_setup" "Code used to setup the inferior Python processes.") (defconst python-shell-eval-setup-code @@ -4639,11 +4643,15 @@ shell has no readline support.") "Detect the readline support for Python shell completion." (let* ((process (python-shell-get-process)) (output (python-shell-send-string-no-output " -try: - import readline - print(readline.get_completer_delims()) -except: - print('No readline support')" process))) +def _PYTHON_EL_detect_readline(): + try: + import readline + print(readline.get_completer_delims()) + except: + print('No readline support') + +_PYTHON_EL_detect_readline() +del _PYTHON_EL_detect_readline" process))) (setq-local python-shell-readline-completer-delims (unless (string-search "No readline support" output) (string-trim-right output)))))