Subject: Re: 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: kobarity <[email-masked]>
Date: Sat, 15 Feb 2025 01:13:55 +0900

Visuwesh wrote:
> >> > 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.
> >
> > Thanks for pointing this out.  So I confirmed that the following
> > workaround is also effective.
> >
> > PYTHONSTARTUP="$(python -m jedi repl)" emacs -nw -Q
> 
> So...what do we do from here?  Unfortunately, I know next to nothing
> about this area to file a sensible bug report myself.

I'm not sure either.  As ipython --simple-prompt does not support
completion, I don't know if using rlcompleter with ipython
--simple-prompt is supported or not.

The direct cause of this problem seems to be that rlcompleter.__main__
is not as expected.  So the following steps enable completion on
ipython --simple-prompt on Python 3.13.

import readline
import rlcompleter
import __main__
rlcompleter.__main__ = __main__
readline.parse_and_bind("tab: complete")

Attached is a test patch that does something similar to this.