PyInquirer icon indicating copy to clipboard operation
PyInquirer copied to clipboard

Default value is not added to answers if when evaluates to False

Open SethMMorton opened this issue 5 years ago • 0 comments

import PyInquirer

answers = PyInquirer.prompt(
    [
        {
            "type": "confirm",
            "message": "Do it:",
            "name": "DO_IT",
            "default: True,
            "when": lambda x: "THING" in x,
        }
    ]
)
print(answers)  # {}

I would have expected the result to be {"DO_IT": True}, because that is the default. My expectation is the default is resolved even if not asked - in fact, it is my opinion that the default is especially important if the question is not asked.

This could be solved by adding the default to the answers dictionary before the when is evaluated.

SethMMorton avatar Aug 25 '20 19:08 SethMMorton