Add EnsureMappings constraint for input with several key-value pairs #289
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.
Fixes #283
This adds anEnsureMappings()
constraint, which closely mimicsEnsureMapping()
, but handles input consisting of multiple key value pairs.I'm not sure if I should take into account the fact that a mapping could get really long, though. I think I could base at least parts of this on
itertools
methods - what do you think about that?Update/Edit: Based on discussions in #290 and here, I have reworked this PR. I would be grateful if someone could check if it contains anything of use - I got entangled a bit too deep have currently lost orientation as for "why" the changes are needed. I'll make attempt to support some of the stuff that
meta-add
is doing, and then I might get the full picture again.The changes I added now are:
EnsureMapping
can not easily be replaced becauseEnsureParameterConstraint
relies on it. The remainder of what I have implemented contains at least parts of its functionality, though, so I'm not sure if my PR adds anything of value.EnsureMapping
, I have for now just added an additionalEnsureNTuple
Constraint that was supposed to replace it inEnsureMapping
->Ensure2Tuple
#290.EnsureNTuple
has the ability to take a list of Constraints, match the constraints to the input values, and returns the outcome as a tuple. The difference between the existingEnsureTupleOf
andEnsureNTuple
is the ability to define different constraints for different items.EnsureIterableOf
in an attempt to reduce code duplication (asEnsureMapping
contained this functionality first).EnsureNTuple
derives fromEnsureIterableOf
to make use of string splitting; however that decision should receive a review because its not really elegant - I needed to initialize the super with aNoConstraint()
to not violate its parameters.EnsureDict
, which returns input as a dict and can apply constraints separately to keys and values. Its similar to the previous attempts ofEnsureMappings
, but does not do any string splitting. This constraint, too, overlaps with whatEnsureMapping
does, so I'm not sure if it has inherent value.Because I'm quite uncertain about the future of any of these changes, I'm putting the PR into draft mode.