-
Notifications
You must be signed in to change notification settings - Fork 2
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
Spec.conform_valid
can now propogate through nested Specs
#67
Draft
chrisrink10
wants to merge
28
commits into
master
Choose a base branch
from
fix/conform-valid-nested
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
chrisrink10
changed the base branch from
fix/override-custom-conformers
to
master
April 21, 2020 23:39
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 PR adds an
IConformer
interface for conformers internally. That interface allows internal custom conformers to propogate calls to e.g.Spec.conform_valid
through other nested Spec conformers. User provided conformers can still be provided as single-argument functions -- they will be wrapped automatically bydataspec
into an implementation ofIConformer
.I considered going the slightly different route of having
dataspec
wrap user functions in another function which discarded theis_valid
keyword argument, provided the user function did not include theis_valid
keyword argument. There's no particularly strong philosophical argument against doing this (and it is my preferred option), but it feels too unreliable to use something likeinspect
at runtime to figure out the signature of a function and dynamically wrap it. We already do this for determining whether to create aPredicateSpec
versus aValidatorSpec
and it feels dirty enough.Fixes #51
MyPy's plugin for
attrs
had a lot of trouble with the types used in this changeset. In particular,make_conformer
is used as the converter for all builtinconformer
attributes and for some reason MyPy simply couldn't handle that. I briefly surveyed some related issues on MyPy's repo and it seems perhaps theattrs
plugin takes some shortcuts for optionals and generics, which may explain our problem.