tmbo / questionary

Python library to build pretty command line user prompts ✨Easy to use multi-select lists, confirmations, free text prompts ...
MIT License
1.53k stars 87 forks source link

Inconsistency in Documentation or Bug for return value of questionary.prompt() after capture of Keyboard Interrupt (ctrl-c) #385

Open pyth0n1c opened 2 months ago

pyth0n1c commented 2 months ago

Describe the bug

The following documentation states that if a keyboard interrupt is captured during a questionary.prompt() call, then None should be returned: https://github.com/tmbo/questionary/blob/cf10f3e650d1550376a8e908baa0c9811ef72041/docs/pages/advanced.rst#safe

However, the codebase shows that if a Keyboard Interrupt is captured, then it is actually an empty dict {} which should be returned: https://github.com/tmbo/questionary/blob/cf10f3e650d1550376a8e908baa0c9811ef72041/questionary/prompt.py#L81

I am unsure if the documentation should be updated to reflect the codebase OR the codebase should be updated to reflect the documentation. The fix is simple.

Example

#Run the following example code on the current `master` branch

import questionary
questionary.prompt([{"type":"text","message":"Just enter any string value", "name":"string_value","default":"some_default_value"}])

#Before answering the question, hit Ctrl-C to generate a keyboard input. You should notice the {}, a dict, is returned.

Steps to reproduce

See the example code above

Expected behaviour

According to the documentation, this should return None, but the code actually returns {}, a dict. I am unsure which is correct, so either the code or documentation should be updated to reflect the intended behavior.

Latest version

Questionary version

2.0.1 (and latest commit in repo master: cf10f3e650d1550376a8e908baa0c9811ef72041)

Prompt Toolkit version

3.0.36

Operating System

macOS