Support defaults via Optional#52
Merged
Merged
Conversation
This will let Optional('foo', default=1) take precedence over simply `str` and thus have the opportunity to insert its default.
The only case for which this should change behavior is if somebody was comparing against a type with a `validate` attr. In that case, the logic would have gone down the wrong path anyway, attempting to call validate() on the type itself.
Then we don't have to filter them back out later.
Error trapping on Optional construction is to follow, split out for ease of review, since it will likely require some refactoring.
… single, static key.
Contributor
Author
|
The reason the defaults are used verbatim, rather than being passed through any value validators, is that it's more convenient in my use cases to come up with a programmatic value than a raw representation. You can always get the opposite behavior by factoring out any validators in question and manually passing a raw value through them. Perhaps more compellingly, inverting the opposite behavior would not always be possible. |
Contributor
Author
|
I believe this also fixes #23. |
Owner
|
Thanks, Erik! |
keleshev
added a commit
that referenced
this pull request
Feb 27, 2015
Support defaults via Optional
Contributor
Author
|
Thanks for the quick merge! :-D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This lets us insert default values for missing dict keys. I independently arrived at this API before seeing that it's also a leading contender in #19, so it's at least unsurprising for 2 people. :-)
I had to do a minor twiddle of prioritization so that more generic keys like
strwouldn't eat the Optionals' lunch, but that shouldn't affect any conceivable non-crashing use case. (See one of the commit messages for details.)