Skip to content

Commit 8ce8250

Browse files
committed
Don't show type checker functions in TypeChecker reprs.
1 parent 6533d32 commit 8ce8250

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

jsonschema/_types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def is_any(checker, instance):
6161
return True
6262

6363

64-
@attr.s(frozen=True)
64+
@attr.s(frozen=True, repr=False)
6565
class TypeChecker:
6666
"""
6767
A :kw:`type` property checker.
@@ -89,6 +89,10 @@ class TypeChecker:
8989
converter=_typed_pmap_converter,
9090
)
9191

92+
def __repr__(self):
93+
types = ", ".join(repr(k) for k in sorted(self._type_checkers))
94+
return f"<{self.__class__.__name__} types={{{types}}}>"
95+
9296
def is_type(self, instance, type: str) -> bool:
9397
"""
9498
Check if the instance is of the appropriate type.

jsonschema/tests/test_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def raises_keyerror(checker, instance):
105105

106106
self.assertIs(context.exception, error)
107107

108+
def test_repr(self):
109+
checker = TypeChecker({"foo": is_namedtuple, "bar": is_namedtuple})
110+
self.assertEqual(repr(checker), "<TypeChecker types={'bar', 'foo'}>")
111+
108112

109113
class TestCustomTypes(TestCase):
110114
def test_simple_type_can_be_extended(self):

0 commit comments

Comments
 (0)