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 code that validates Schema classes when they're instantiated, rather than only when they're converted to a dictionary. This significantly improves the user experience (see examples below)
The downsides of this change are:
SchemaBase
to accomplish this, and to make certain this kind of validation is disabled in cases that it causes issues (for example, when you do something likeencode(x='Origin')
, the encoding is not valid until you can add type information, which requires data that may not be available until the final serialization).type
is required by the schema at the time it's instantiated. I've disabled this validation check on all top-level objects ('Chart', 'LayeredChart', 'X', 'Color', etc.), and I think that covers 99% of the cases where people use this pattern.I think those downsides are worth swallowing for the added usability of informative error messages. In case performance is critical, I added a
DEBUG_MODE
flag that can be set to False; when it is, the chart will only be validated once, after the final serialization is constructed.Previous behavior
Before this PR, if you make a mistake somewhere deep in the chart, this is the kind of traceback you get:
Not much specific information about where the code went wrong... it basically spits out the entire chart serialization and tells you that it's invalid, and it's up to you to decipher why.
After this PR, the behavior looks like this:
The error is raised when the class is instantiated, which means you have the Python code context to help you figure out where things went wrong.