Fix IndentationError when a subschema generates no validation code - #206
Merged
Conversation
Owner
|
Thank you! |
This file contains hidden or 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
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.
compile()generates invalid Python for some valid schemas:Any truthy subschema that produces no validation code triggers this: annotation-only schemas (
title,description,$comment, ...), unknown keywords, or no-op keywords such as{"not": false},{"uniqueItems": false}, or an unrecognizedformat(a no-op since 63e29e3). The generator emits a block header with nothing under it.This is the same class as #204/#205, so I probed every subschema position of every generator with code-less subschemas across drafts 04/06/07/2019. Seven sites are affected:
not(try body) — unguardedthenandelseof if-then-else — 263ecad guarded only theifblockdependencies— unguardeditems,additionalItems,propertyNames— guarded, but by the number of keyword functions run (the return value ofgenerate_func_code_block), which misses keywords that run and emit nothing:{"items": {"not": false}}still crashedThe fix applies the
code_lensnapshot pattern from 263ecad at all seven sites, replacing the count-based guards. The remaining generators (anyOf/oneOf/contains/properties/patternProperties/additionalProperties) always emit at least one body line and were verified unaffected.This also fixes the compile crash on the suite's
optional/unknownKeyword.json— three of its cases now pass, but the file has to stay inignored_suite_filesbecause its other cases need$ref-to-embedded-$idresolution, which is a separate gap.Independent of #181, which fixes a different
generate_notbug (not: {}accepting falsy instances); the two compose.