Skip to content

Commit b5341be

Browse files
committed
Remove duplication
1 parent 7f2268c commit b5341be

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

docs/validate.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ be enabled by hooking in a format-checking object into an :class:`IValidator`.
183183

184184
.. autoclass:: FormatChecker
185185
:members:
186+
:exclude-members: cls_checks
186187

187188
.. attribute:: checkers
188189

@@ -191,6 +192,16 @@ be enabled by hooking in a format-checking object into an :class:`IValidator`.
191192
for all checkers using the :meth:`FormatChecker.checks` or
192193
:meth:`FormatChecker.cls_checks` decorators respectively.
193194

195+
.. method:: cls_checks(format)
196+
197+
Register a decorated function as *globally* validating a new format.
198+
199+
Any instance created after this function is called will pick up the
200+
supplied checker.
201+
202+
:argument str format: the format that the decorated function will check
203+
204+
194205

195206
There are a number of default checkers that :class:`FormatChecker`\s know how
196207
to validate. Their names can be viewed by inspecting the

jsonschema.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -517,23 +517,6 @@ def __init__(self, formats=None):
517517
else:
518518
self.checkers = dict((k, self.checkers[k]) for k in formats)
519519

520-
@classmethod
521-
def cls_checks(cls, format):
522-
"""
523-
Register a decorated function as *globally* validating a new format.
524-
525-
Any instance created after this function is called will pick up the
526-
supplied checker.
527-
528-
:argument str format: the format that the decorated function will check
529-
530-
"""
531-
532-
def _checks(func):
533-
cls.checkers[format] = func
534-
return func
535-
return _checks
536-
537520
def checks(self, format):
538521
"""
539522
Register a decorated function as validating a new format.
@@ -547,6 +530,8 @@ def _checks(func):
547530
return func
548531
return _checks
549532

533+
cls_checks = classmethod(checks)
534+
550535
def conforms(self, instance, format):
551536
"""
552537
Check whether the instance conforms to the given format.

0 commit comments

Comments
 (0)