Subject: bug#50503: [PATCH] Properly encode all strings sent to the Python shell

From: Augusto Stoffel <[email-masked]>
Date: Sat, 11 Sep 2021 15:32:26 +0200

On Sat, 11 Sep 2021 at 14:45, Lars Ingebrigtsen <[email-masked]> wrote:

> Augusto Stoffel <[email-masked]> writes:
>
>> If it is stylistically acceptable, I think
>>
>>   (or (bound-and-true-p comint-max-line-length) 1024)
>>
>> is the simplest solution.  One could also replace the mysterious 1024 by
>> 0, which was more or less the previous situation anyway.
>
> Sure, that'd be fine.

I've attached a patch

>From d2a6bd70d19f84592235691eb25356bcc5275880 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Sat, 11 Sep 2021 15:29:06 +0200
Subject: [PATCH] Keep python.el compatible with older Emacsen

* progmodes/python.el (python-shell-send-string): Don't assume
comint-max-line-length is defined.
---
 lisp/progmodes/python.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e71a8102df..b17d740036 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3155,7 +3155,9 @@ python-shell-send-string
                       (python-shell--encode-string (or (buffer-file-name)
                                                        "<string>")))))
     (if (or (null (process-tty-name process))
-            (<= (string-bytes code) comint-max-line-length))
+            (<= (string-bytes code)
+                (or (bound-and-true-p comint-max-line-length)
+                    1024))) ;; For Emacs < 28
         (comint-send-string process code)
       (let* ((temp-file-name (with-current-buffer (process-buffer process)
                                (python-shell--save-temp-file string)))
-- 
2.31.1