Skip to content

Commit

Permalink
Minor non-functional changes to FormatChecker docstrings and __init__.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Aug 30, 2022
1 parent a513c99 commit fd491f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/validate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ By default, no validation is enforced, but optionally, validation can be enabled
:exclude-members: cls_checks

.. attribute:: checkers

A mapping of currently known formats to tuple of functions that validate them and errors that should be caught.
New checkers can be added and removed either per-instance or globally for all checkers using the `FormatChecker.checks` decorator.

Expand Down
20 changes: 9 additions & 11 deletions jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ class FormatChecker:
`FormatChecker` objects always return ``True`` when asked about
formats that they do not know how to validate.
To check a custom format using a function that takes an instance and
returns a ``bool``, use the `FormatChecker.checks` or
`FormatChecker.cls_checks` decorators.
To add a check for a custom format use the `FormatChecker.checks`
decorator.
Arguments:
formats (~collections.abc.Iterable):
formats:
The known formats to validate. This argument can be used to
limit which formats will be used during validation.
Expand All @@ -47,9 +46,8 @@ class FormatChecker:

def __init__(self, formats: typing.Iterable[str] | None = None):
if formats is None:
self.checkers = self.checkers.copy()
else:
self.checkers = dict((k, self.checkers[k]) for k in formats)
formats = self.checkers.keys()
self.checkers = {k: self.checkers[k] for k in formats}

def __repr__(self):
return "<FormatChecker checkers={}>".format(sorted(self.checkers))
Expand All @@ -62,11 +60,11 @@ def checks(
Arguments:
format (str):
format:
The format that the decorated function will check.
raises (Exception):
raises:
The exception(s) raised by the decorated function when an
invalid instance is found.
Expand Down Expand Up @@ -117,7 +115,7 @@ def check(self, instance: object, format: str) -> None:
The instance to check
format (str):
format:
The format that instance should conform to
Expand Down Expand Up @@ -150,7 +148,7 @@ def conforms(self, instance: object, format: str) -> bool:
The instance to check
format (str):
format:
The format that instance should conform to
Expand Down

0 comments on commit fd491f9

Please sign in to comment.