homepage

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: readline completer could return an iterable
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: josh.r, nicolas_49
Priority: normal Keywords:

Created on 2012年02月05日 19:48 by nicolas_49, last changed 2022年04月11日 14:57 by admin.

Messages (3)
msg152703 - (view) Author: Nicolas (nicolas_49) Date: 2012年02月05日 19:48
The function set by readline.set_completer must return one completion per call. This should be great if we can return an iterable, because with current implementation I have to write a wrapper:
cache = None
def completer(text, state):
 if cache:
 if len(cache) > 0:
 return cache.pop(0)
 else:
 cache = None
 return None
 res = completer_returning_iterable(text)
 if isinstance(res, str) or res == None:
 return res
 cache = res
 return completer(text, state)
readline.set_completer(completer)
And completer_returning_list, the true completer, returns a pythonic iterable for all possible completion.
msg222161 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014年07月03日 08:41
Is this a good, bad or indifferent idea?
msg222253 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2014年07月04日 01:08
I agree the design requiring it to pass the same information over and over is a bit odd (I've occasionally had cause to "borrow" some of ipython's niftyness for a plain Python terminal, and making custom completers work is one of the more awkward parts of the whole process). I'm guessing this is a product of conforming overzealously to the C API for readline functions like rl_filename_completion_function (see: http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC47 ).
It doesn't seem possible to do this nicely; __next__() on a generic iterator won't accept arguments (and practically, one of these arguments is state, the other is just "get next"), and trying to catch a TypeError due to the wrong number of arguments or using a generator as a string so you switch modes is ugly. Either the existing interface spawns additional arguments (also ugly; boolean flags that completely change behavior are the last refuge of a scoundrel), or a new function is created (possibly deprecating the old one over time.
Any suggestions?
History
Date User Action Args
2022年04月11日 14:57:26adminsetgithub: 58154
2019年03月16日 00:13:17BreamoreBoysetnosy: - BreamoreBoy
2014年07月04日 01:08:09josh.rsetnosy: + josh.r
messages: + msg222253
2014年07月03日 08:41:32BreamoreBoysetnosy: + BreamoreBoy

messages: + msg222161
versions: + Python 3.5, - Python 3.3
2012年02月12日 04:22:42terry.reedysetversions: + Python 3.3, - Python 3.1
2012年02月05日 19:48:01nicolas_49create

AltStyle によって変換されたページ (->オリジナル) /