Full subclass support for nested schemas. #268
Merged
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.
Hi,
I have encounter some issues in integrating this package with the python's new dataclasses.dataclass. Most of them is due to the lack of customizability of the core classes including
Schema
,Optional
, etc.This pull request contains the following changes:
**kwargs
to the function signature ofSchema.validate()
. This allows subclass to override the behavior ofvalidate
in a propagate-able fashion. Nestedschema.Schema
class will ignore any kwargs, but nestedMySchema
class will behave accordingly. This fix A post validation hook at the schema level would be handy. #262 (@tolomea). Moreover, the kwargs passed tovalidate()
is picked up by theOptional(default=)
value when it is a callable:Optional
is not allowed #265 (@raoyitao), by changing the the hardcoded type check forOptional
. This allows one to implement MyOptional that consumes the kwargs passed fromvalidate
to callable default more integrated:**kwargs
to the signature ofSchema.json_schema()
, and changed the handling of default values such that callable will be evaluated with the kwargs. This makes it more inline with the behavior of theSchema.validate
:For more details of the changes and their implications, please take a look at the test cases I added.
Please let me know what you think!