questionary icon indicating copy to clipboard operation
questionary copied to clipboard

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

Open pyth0n1c opened this issue 7 months ago • 0 comments

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

  • [X] I have checked that this issue occurs on the latest version of questionary.

Questionary version

2.0.1 (and latest commit in repo master: cf10f3e650d1550376a8e908baa0c9811ef72041)

Prompt Toolkit version

3.0.36

Operating System

macOS

pyth0n1c avatar Jul 17 '24 00:07 pyth0n1c