prompt-toolkit / prompt-toolkit/python-prompt-toolkit
async completer / validator?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
When using prompt_async, this allows to prompt for user input without blocking, but currently, it doesn't seem to allow using a custom completer/validator. Is that correct?
This would be useful for server-side auto-complete, eg when the object set is big/dynamic.
Eg consider
class AsyncNumberValidator(Validator):
def __init__(self, session):
self._session = session
Validator.__init__(self)
async def validate(self, document):
print('AsyncNumberValidator.validate')
res = await self._session.call(u'com.example.validate_int', document.text)
print(res)
return res
used as in
x = await prompt_async('x: ', validator=AsyncNumberValidator(self), patch_stdout=False)
produces:
(cpy360_4) oberstet@office-corei7:~/scm/crossbario/crossbar-examples/prompt$ python client.py
Connected!
x: 23/home/oberstet/cpy360_4/lib/python3.6/site-packages/prompt_toolkit/buffer.py:1103: RuntimeWarning: coroutine 'AsyncNumberValidator.validate' was never awaited
self.validator.validate(self.document)
x: 23
RPC succeded: 23 + 1 = 24
(cpy360_4) oberstet@office-corei7:~/scm/crossbario/crossbar-examples/prompt$ python client.py
Connected!
x: sdfsdf/home/oberstet/cpy360_4/lib/python3.6/site-packages/prompt_toolkit/buffer.py:1103: RuntimeWarning: coroutine 'AsyncNumberValidator.validate' was never awaited
self.validator.validate(self.document)
x: sdfsdf
2017-02-22T18:02:51 Task exception was never retrieved
future: <Task finished coro=<MyComponent.onJoin() done, defined at client.py:41> exception=ValueError("invalid literal for int() with base 10: 'sdfsdf'",)>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the prompt_async example with AsyncNumberValidator and inspect how the validator is called in buffer.py, where the RuntimeWarning is reported. Trace prompt_async's handling of custom validators and completers, then verify that asynchronous callbacks are awaited and invalid input is handled without an unawaited-coroutine warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100