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.
  
    
  
    
Closes #1365
jsonschema/tests/test_validators.py
Adds a test method for the expected behavior, and reverences the issue being solved. The method is slightly longer than others to avoid
TestValidationErrorMessages.message_for, which asserts that there be exactly one error.jsonschema/_keyword.py
The
Keywordclass can define additional tags/behavior for the implementation of the keyword. For now, I have only added a "needs" label, which names other keywords that it cannot be executed before. The name "needs" may be inaccurate, and I'd be happy to change it.The
keyworddecorator makes it trivial to annotate a function to be used as a validator keyword.keywordandKeywordare both optional and completely back-compatible. They would only be necessary for new behavior. There is no change to existing validator function behavior.jsonschema/validators.py
The only changed behavior is that the
iter_errorsevaluatesKeywords after theirneeds. The logic is not as clean as I'd like, but is reasonably straightforward:todokeywords.todo.Keywordthatneedsatodokeyword is labeleddependentand skippeddependentof each other, there is a circular dependency and an error is raised.dependentkeywords are re-attempted.I'd be happy to add comments or a docstring to make the code more self-descriptive if necessary.
📚 Documentation preview 📚: https://python-jsonschema--1366.org.readthedocs.build/en/1366/