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

Add FORMAT_CHECKER attribute for Validator #905

Merged
merged 3 commits into from Jan 31, 2022
Merged

Add FORMAT_CHECKER attribute for Validator #905

merged 3 commits into from Jan 31, 2022

Conversation

TiborVoelcker
Copy link
Contributor

Implement an FORMAT_CHECKER attribute for the Validator class. This allows to use the format_checker of an automatically detected validator like so:

from jsonschema.validators import validator_for

Validator = validator_for(schema)
Validator(schema, format_checker=Validator.FORMAT_CHECKER).validate(instance)

@codecov
Copy link

codecov bot commented Jan 16, 2022

Codecov Report

Merging #905 (36291ae) into main (6787b21) will decrease coverage by 0.02%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #905      +/-   ##
==========================================
- Coverage   97.05%   97.02%   -0.03%     
==========================================
  Files          20       20              
  Lines        3290     3295       +5     
  Branches      457      458       +1     
==========================================
+ Hits         3193     3197       +4     
  Misses         77       77              
- Partials       20       21       +1     
Impacted Files Coverage Δ
jsonschema/validators.py 97.09% <80.00%> (-0.33%) ⬇️
jsonschema/protocols.py 87.50% <100.00%> (+0.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6787b21...36291ae. Read the comment docs.

@TiborVoelcker
Copy link
Contributor Author

Hey @Julian. Just so you know: altough I have been coding with Python for a couple of years, this is my first PR to a public repo, so I do not know what I am doing^^

I only did a few minor changes, but it did seem to work with the syntax you provided in #861.
Please let me know if I missed something, or whatever else.

@Julian
Copy link
Member

Julian commented Jan 16, 2022

Wonderful, I'm sure it's great! Will have a look, do ping me if I don't do so and give you feedback in the next few days or so as I've got a lot of different things all stealing attention but yeah really appreciated!

@Julian Julian merged commit 4369a15 into python-jsonschema:main Jan 31, 2022
@Julian
Copy link
Member

Julian commented Jan 31, 2022

@TiborVoelcker Sorry for the delay in merging. This was perfect, well done.

Julian added a commit that referenced this pull request Sep 9, 2022
Format support / enablement will change with vocabulary support,
but in the interim, now that #905 is merged, these objects are
better accessed by retrieving them directly from the corresponding
validator.

In other words: don't do:

    from jsonschema import draft202012_format_checker

just do

    from jsonschema import Draft202012Validator
    do_whatever_with(Draft202012Validator.FORMAT_CHECKER)
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

Successfully merging this pull request may close these issues.

None yet

2 participants