This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tab-completion of callables displays opening paren
Type: behavior Stage:
Components: Library (Lib) Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dieresys, eric.araujo, facundobatista, georg.brandl, gpolo, martin.panter, pitrou, r.david.murray, rnd0110, wpettersson
Priority: normal Keywords:

Created on 2012-05-11 12:16 by wpettersson, last changed 2022-04-11 14:57 by admin.

Messages (4)
msg160412 - (view) Author: w.pettersson (wpettersson) Date: 2012-05-11 12:16
With tab completion enabled via rlcompleter and readline, tab-completion will assume anything that is callable (by callable(val)) is going to be called. For example, the below code defines a class "CCC" that is callable and has a static function. However, typing 
>>> CC
and then pressing tab results in the following.
>>> CCC(
Note the extra parentheses. It would be nice if these weren't added if the object also has some other reasonable choices.

However, I don't know what would be "reasonable" here. Somehow we'd have to detect whether a callable class has static methods, possibly via dir() or directly checking class.__dict__ but at this point I am not comfortable enough with python to suggest decent solutions.


>>> class CCC:                                                                       
...   def __call__(self):
...     print "call"
...   @staticmethod
...   def f(a):
...     print "Static",a
... 
>>>CC<TAB>
>>>CCC(
msg160420 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-05-11 16:41
This annoys me too, for all callable objects actually (e.g. I type "help(someprefix" then Tab then I have to delete the "(" before typing ")" and Enter), but I think it was a deliberate change.  I may have the original bug report open in a browser tab at home, I’ll check.
msg160633 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-05-14 16:11
It's issue 449227.
msg265472 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-13 12:51
FWIW, count me against the automatic brackets as well. Another way it gets in the road:

>>> class C(object(. . .

In Issue 5062, Carl thought there might be a switch to turn the behaviour off. Perhaps we could add some sort of configuration option.
History
Date User Action Args
2022-04-11 14:57:30adminsetgithub: 58987
2016-05-13 12:51:25martin.pantersetmessages: + msg265472
2015-02-11 10:56:25martin.pantersetnosy: + martin.panter
2012-05-14 16:11:38r.david.murraysetnosy: + rnd0110, dieresys, facundobatista, pitrou, gpolo, r.david.murray, georg.brandl
messages: + msg160633
2012-05-11 16:41:32eric.araujosettitle: Tab-completion of classes displays opening paren -> Tab-completion of callables displays opening paren
2012-05-11 16:41:09eric.araujosetnosy: + eric.araujo

messages: + msg160420
title: Tabcompletion of classes with static methods and __call__ has extra bracket -> Tab-completion of classes displays opening paren
2012-05-11 12:16:25wpetterssoncreate