-
-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: require answer for questions without default value #958
fix: require answer for questions without default value #958
Conversation
Codecov Report
@@ Coverage Diff @@
## master #958 +/- ##
==========================================
+ Coverage 96.24% 96.34% +0.10%
==========================================
Files 42 44 +2
Lines 3169 3448 +279
==========================================
+ Hits 3050 3322 +272
- Misses 119 126 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 11 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
For int and float, the default could be 0. And for Json, null. If we do it like that, we avoid the errors. What do you think? |
I think using 0 as a default value for After giving this some more thought and reading #355 (comment) again, I think whether the correct/consistent solution is this: The In interactive mode, there are some implicit initial values/selections:
For That said, I don't agree with
because WDYT? |
So,
I agree. For a required str question, just add `validator: '{% if not answer %}Required{% endif %}'. It's not as ergonomic, but works and is simpler to maintain upstream. |
This behavior is documented in the YAML spec, so I think we should respect the spec and let empty strings become |
Correct.
I hadn't thought about that. Right, the spec should certainly be respected. 👍 |
I've made the changes as we discussed. Any question that has no The implementation of this behavior requires a new value that has the semantics "not set" for the value of the A few tests require adjustment to the new behavior because they rely on the default answer to a question without a WDYT, @yajo? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Would you please fix the conflics to merge? |
Done. And I've also added type hints and made some minor stylistic improvements. |
I just pushed a commit that removes obsolete special treatment of |
I've fixed the behavior for questions without a default value when no answer is provided in the interactive questionnaire.
The new behavior is:
type: str
question:""
type: yaml
question:None
(result ofyaml.safe_load("")
)type: int
/type: float
/type: json
question: Validation errorInvalid input
type: bool
question:False
(implicit default)choice: ...
question: The first choice (implicit default).I think this new behavior is more intuitive and expected than the current one.
Fixes #355 #956.
Note: This PR does not change the behavior when the
--default
flag is passed because it is not yet clear how to deal with questions that lead to a validation error when no default value exists.