summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2022-08-30 11:05:35 +0300
committerJulian Berman <Julian@GrayVines.com>2022-08-30 11:05:35 +0300
commitfd491f971e7197329e200df1f98fcb6e39779bd7 (patch)
tree4100e27f4a3347799912af33d91ec89cd5c4c0e3
parenta513c99fdae54cbfe633a9de0a0d542a5ba5a545 (diff)
downloadjsonschema-fd491f971e7197329e200df1f98fcb6e39779bd7.tar.gz
Minor non-functional changes to FormatChecker docstrings and __init__.
-rw-r--r--docs/validate.rst1
-rw-r--r--jsonschema/_format.py20
2 files changed, 10 insertions, 11 deletions
diff --git a/docs/validate.rst b/docs/validate.rst
index 870735b..50580bd 100644
--- a/docs/validate.rst
+++ b/docs/validate.rst
@@ -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.
diff --git a/jsonschema/_format.py b/jsonschema/_format.py
index ad8343b..2c07719 100644
--- a/jsonschema/_format.py
+++ b/jsonschema/_format.py
@@ -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.
@@ -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))
@@ -62,11 +60,11 @@ class FormatChecker:
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.
@@ -117,7 +115,7 @@ class FormatChecker:
The instance to check
- format (str):
+ format:
The format that instance should conform to
@@ -150,7 +148,7 @@ class FormatChecker:
The instance to check
- format (str):
+ format:
The format that instance should conform to