Skip to content
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
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

chrisrink10
Copy link
Contributor

@chrisrink10 chrisrink10 commented Apr 21, 2020

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 by dataspec into an implementation of IConformer.

I considered going the slightly different route of having dataspec wrap user functions in another function which discarded the is_valid keyword argument, provided the user function did not include the is_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 like inspect at runtime to figure out the signature of a function and dynamically wrap it. We already do this for determining whether to create a PredicateSpec versus a ValidatorSpec 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 builtin conformer 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 the attrs plugin takes some shortcuts for optionals and generics, which may explain our problem.

@chrisrink10 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
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Spec.conform_valid does not propogate beyond collection, dict, and tuple specs
1 participant