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

validate() api considerations #59

Open
wbolster opened this issue Mar 16, 2019 · 2 comments
Open

validate() api considerations #59

wbolster opened this issue Mar 16, 2019 · 2 comments

Comments

@wbolster
Copy link
Contributor

hey,

i'm wondering what made you decide to use a classmethod for Schema.validate() which then returns an instance of the schema.

i am wondering how this would work nicely when you're actually interested in creating custom (application specific) class instances, such as sqlalchemy orm class instances (‘database models’), since all attributes need to be copied afterwards.

also, to me ‘an instance of a schema’ is not the obvious answer for the question ‘what's the result of my validation’, yet typesystem seems to think that is fine.

just curious to hear your thoughts. thanks in advance!

@tomchristie
Copy link
Member

Actually I think this might be a point worth considering.

You'll get a better idea of why I'd taken this path if you look at how orm is using typesystem https://github.com/encode/orm - in that case Model inherits from Schema.

It's useful having Schema classes be able to act like classes with fine-grained type validation, plus being able to use them in type annotations, but I can see arguments in favor of the other style too.

Options will be, either:

  • Include a cast=... argument in order to allow casting to some other type.
  • Switch schemas so that .validate is an instance method, and they return dicts by default, with controls for changing that behavior. (More in line with eg. Marshmallow)

@skewty
Copy link
Contributor

skewty commented Apr 2, 2019

Further to what @tomchristie said, what helped me understand his reasoning was a few remarks in the documentation about the treatment of a similar class instance or dict passed to __init__() (validation is not done). This allows for a faster code path option; you get to choose if you need validation or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants