Subject: bug#76205: 31.0.50; 31.0.50; python.el completion broken for non-builtin objects in IPython 8.30.0 & Python 3.13.2

From: Liu Hui <[email-masked]>
Date: Thu, 13 Feb 2025 11:47:00 +0800

On Wed, Feb 12, 2025 at 11:03 PM kobarity <[email-masked]> wrote:
>
> Eli Zaretskii wrote:
> >
> > > From: Visuwesh <[email-masked]>
> > > Date: Tue, 11 Feb 2025 20:37:22 +0530
> > >
> > > I am unsure if this is a me problem but I can no longer complete
> > > non-builtin objects in a python-mode buffer when I'm using the specified
> > > IPython&Python version combination.  However, if I don't use IPython,
> > > then completion does work as expected.  It prints the following message
> > > though (not sure if it is related):
> > >
> > >     Python 3.13.2 (main, Feb  5 2025, 01:23:35) [GCC 14.2.0] on linux
> > >     Type "help", "copyright", "credits" or "license" for more information.
> > >     warning: can't use pyrepl: terminal doesn't have the required clear capability; TERM=dumb
> > >     >>>
> > >
> > > To reproduce the issue,
> > >
> > >     1. emacs -Q
> > >     2. Open a python buffer.
> > >     3. Type in "import numpy as np" in the buffer.
> > >     4. Say C-u C-c C-p, answer ipython3 --simple-prompt -i to the first
> > >        prompt, then say no to the second.
> > >     5. After the *Python* is created, say C-c C-c in the python-mode
> > >        buffer.
> > >     6. Now type "np." and say M-TAB.
> > >     7. Observe how no completion candidates are offered.
> > >     8. Remove "np." and instead type "pr" and say M-TAB.
> > >     9. Observe how two completion candidates (print and property) are
> > >        offered.
> > >     10. Repeat the same without using IPython and observe how
> > >         python-mode offers completion after "np."
> > >
> > > I am on Debian sid with an "apt update && apt upgrade" today some 15
> > > mins ago (no luck after updating if I wasn't clear enough) if it
> > > matters.
> >
> > Thanks.
> >
> > kobarity, any comments or suggestions?
>
> I reproduced the issue with IPython 8.32.0 and Python 3.13.2.  It
> seems that there is no problem with IPython on Python 3.12.
>
> One workaround is to disable native completion:
> M-x python-shell-completion-native-turn-off
> It will be a little more inconvenient than the native completion.
>
> We need to investigate the cause.
>
> Liu Hui, do you have any idea?

The problem seems to be not related to emacs, because the completion
of non-builtin objects doesn't work in terminal too (IPython 8.32.0
and Python 3.13.2):

1. run ipython in a terminal: ipython3 --simple-prompt -i

2. type the following code:
   import readline
   import rlcompleter
   readline.parse_and_bind("tab: complete")
   import numpy as np

3. type np.<TAB>, there is no completion

If I change the completer to others (e.g. jedi):
   from jedi.utils import setup_readline
   setup_readline()

then the completion works in both terminal and emacs.