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: Visuwesh <[email-masked]>
Date: Sat, 15 Feb 2025 18:04:09 +0530

[சனி பிப்ரவரி 15, 2025] kobarity wrote:

>> [...]
>> 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.

I can confirm that completion works for non-builtin objects with this
patch.

> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index 8a99ff0434d..2563044c0ee 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -4534,6 +4534,12 @@ python-shell-completion-native-setup
>              if not is_ipython:
>                  readline.set_completer(new_completer)
>              else:
> +                import sys
> +                import __main__
> +                try:
> +                    sys.modules['rlcompleter'].__main__ = __main__
> +                except KeyError:
> +                    pass
>                  # Try both initializations to cope with all IPython versions.
>                  # This works fine for IPython 3.x but not for earlier:
>                  readline.set_completer(new_completer)