Subject: bug#68559: [PATCH] Improve Python shell completion

From: kobarity <[email-masked]>
Date: Fri, 16 Feb 2024 18:34:25 +0900

Liu Hui wrote:
> On Thu, Feb 15, 2024 at 10:43 PM Mattias Engdegård
> <[email-masked]> wrote:
> >
> > The recent change on master, 0b9c7148fd, causes several failures in python-tests here (macOS). Log attached.
> >
> > It seems to have something to do with completion. Maybe the new code is sensitive to details of Python's command line editor? The standard Python interpreter is unlikely to use GNU readline, for example.
> 
> Hi,
> 
> According to the log, the problem may be related to the json library,
> which is introduced by the patch to convert the completion results
> from Python to elisp. What is the version of Python on macOS? AFAIK
> the json library is added to the Standard library since version 2.6.
> If the library is not available, could you setup a Python virtual
> environment containing the library and run the python tests in it?
> Thanks!

This is caused by the fact that the input is echoed back on MacOS
Python.  This is described in etc/PROBLEMS:

*** In Inferior Python mode, input is echoed and native completion doesn't work.

The following log shows that it tries to parse the echoed back string
as a JSON string.

Test python-completion-at-point-1 backtrace:
  json-parse-string("__PYTHON_EL_eval_file(\"/var/folders/qy/zstv16390
  python--parse-json-array("__PYTHON_EL_eval_file(\"/var/folders/qy/zs

I think the echoed back string were ignored before the patch is
applied.  However, after applying the patch, the returned string is
now parsed as JSON, which I believe is the reason for the error.

So one workaround would be to remove the echoed back string before
parsing as JSON.