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

From: kobarity <[email-masked]>
Date: Sun, 28 Jan 2024 22:22:11 +0900

Liu Hui wrote:
> kobarity <[email-masked]> 于2024年1月25日周四 23:38写道：
> > 1. Module names cannot be completed in Python buffer.
> Can you elaborate? The completion of module names never worked for me
> except using IPython with non-native completion mechanism.
> 
> Because module names cannot be completed using vanilla python
> interpreter in the terminal, they are also not completed even with the
> patch, unless jedi is available.

Hmm, I must have done something wrong.  I cannot reproduce the problem
of module name completion even with the previous patch.
As for the current python-mode, I was able to complete the module
names because I enabled Jedi in PYTHONSTARTUP.  Sorry for the confusion.

I'm experiencing strange behavior regarding completion of import
statement in a block in Python buffer.  If I try to type the following
lines and then try to complete it, it will fail.

#+begin_src python
try:
    im
#+end_src

However, when I try to complete at the beginning of the second line:

#+begin_src python
try:
    
#+end_src

"import" keyword also appears as a candidate.  If I cancel the
candidates and type "im" and try to complete it, it will succeed.
This behavior does not occur in Python Shell buffer.

Another thing I noticed is the multi-line import statement.  If the
import statement is one-line, each items (IGNORECASE and MULTILINE in
the example below) can be completed.

#+begin_src python
from re import IGNORECASE, MULTILINE
#+end_src

However, they cannot be completed if the import statement spans
multi-line.

#+begin_src python
from re import (
    IGN
#+end_src

This happens in both Python buffer and Python Shell buffer.  Perhaps
this is a limitation of Jedi completer?

> > 2. Completion is not working in comments.
> >
> > I'm not sure if the completion should work in comments, but some
> > people might want it because the current python-mode allows it in both
> > Python buffer and Python Shell buffer.
> 
> Thanks for pointing it out. The attached patch should now restore
> previous basic completion behavior in comments.

Thanks, I confirmed that basic completion (without keyword argument
completion) can be performed within comments.