Prioritize Optionals based on one level of depth traversal. Close #44, #45.#54
Prioritize Optionals based on one level of depth traversal. Close #44, #45.#54erikrose wants to merge 2 commits into
Conversation
…eshev#44, keleshev#45. This enables the common pattern in which there's a 'foo' key with a default and we also take arbitrary other, optional str keys. We turn priority() into a delegating "generic function", like len(). This lays the groundwork to go deeper--with any "flavor", not just Optionals. First, we'd want to refactor Schema.validate() so it constructs actual Schema subclasses all the time rather than handling many cases inline. For sets, for example, it would construct an Iterable, and Iterable.priority() would know how to tunnel one level inside itself to return a compound priority. Then we could prioritize Optional((1, 0)) over Optional((int,)). The behavior of And() and Or() (and iterables) are up for grabs: perhaps go with the priority of the most specific item inside?
|
Here's one more for you, Vladimir. What do you think? I'm rather enthused to do the mentioned refactoring as well, if you like. |
49ae7f0 to
99dc413
Compare
|
Love the idea of including
With each of the What do you think? |
|
Not to forget, but a minor concern: if priority becomes part of public interface, then we should see if there's anything better than |
|
Oh, my! I should have read your #55 first :-) |
This enables the common pattern in which there's a 'foo' key with a default and we also take arbitrary other, optional str keys.
We turn priority() into a delegating "generic function", like len().
This lays the groundwork to go deeper--with any "flavor", not just Optionals. First, we'd want to refactor Schema.validate() so it constructs actual Schema subclasses all the time rather than handling many cases inline. For sets, for example, it would construct an Iterable, and Iterable.priority() would know how to tunnel one level inside itself to return a compound priority. Then we could prioritize Optional((1, 0)) over Optional((int,)). The behavior of And() and Or() (and iterables) are up for grabs: perhaps go with the priority of the most specific item inside?