Skip to content

Commit

Permalink
Don't show type checker functions in TypeChecker reprs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Aug 30, 2022
1 parent 6533d32 commit 8ce8250
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jsonschema/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def is_any(checker, instance):
return True


@attr.s(frozen=True)
@attr.s(frozen=True, repr=False)
class TypeChecker:
"""
A :kw:`type` property checker.
Expand Down Expand Up @@ -89,6 +89,10 @@ class TypeChecker:
converter=_typed_pmap_converter,
)

def __repr__(self):
types = ", ".join(repr(k) for k in sorted(self._type_checkers))
return f"<{self.__class__.__name__} types={{{types}}}>"

def is_type(self, instance, type: str) -> bool:
"""
Check if the instance is of the appropriate type.
Expand Down
4 changes: 4 additions & 0 deletions jsonschema/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def raises_keyerror(checker, instance):

self.assertIs(context.exception, error)

def test_repr(self):
checker = TypeChecker({"foo": is_namedtuple, "bar": is_namedtuple})
self.assertEqual(repr(checker), "<TypeChecker types={'bar', 'foo'}>")


class TestCustomTypes(TestCase):
def test_simple_type_can_be_extended(self):
Expand Down

0 comments on commit 8ce8250

Please sign in to comment.