[Python-ideas] Open parenthesis in REPL completion

Steven D'Aprano steve at pearwood.info
Mon May 6 19:28:45 EDT 2019


On Thu, Apr 25, 2019 at 02:42:09PM +0100, Stefano Borini wrote:

> PyCharm adds the parenthesis, but also adds the end parenthesis, so
> the whole use of parentheses is consistent: the user has not to worry
> about them.
> Bash refuses to guess when it's ambiguous, and stops until you fill
> the ambiguous part.

In Python, functions are first-class values, so parentheses or not is 
*always* ambiguous. If I start typing the name of a function, there is 
no way for the REPR to know whether I want to call the function or refer 
to it as an object.

Although it might *guess* that calling a function is more common than 
treating it as a value.


> Right now, the REPL implements a mixed situation where it both assumes
> your usage, and does not help you all the way through. Although we can
> all agree that functions most of the time are invoked, rather than
> used as is.
> IMHO, either the parenthesis should not be added, or two parentheses
> should be added and the cursor placed in the center (I am unsure about
> the details of the REPL implementation, but I guess it's possible) at
> least to have a consistent experience.

How ironic if a request on Python-Ideas to *stop* adding the opening 
parenthesis leads to the REPR adding the closing parenthesis as well.

The more I think about it, the more I suspect the least-worst solution 
will be to make tab-completion configurable, with three options:

- no parentheses
- both parentheses
- only the opening parenthesis (status quo)

and an API to set the behaviour at startup depending on an environment 
variable or a config file.

Anyone want to propose a patch?



-- 
Steven


More information about the Python-ideas mailing list