Skip to content

Unknown type not being treated as 'any' #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def __init__(self, schema, types=(), resolver=None):

self._types = dict(self.DEFAULT_TYPES)
self._types.update(types)
self._types["any"] = tuple(self._types.values())

if resolver is None:
resolver = RefResolver()
Expand All @@ -139,9 +138,11 @@ def is_type(self, instance, type):

"""

if type not in self._types:
raise UnknownType(type)
type = self._types[type]
type = self._types.get(type, "any")

# If type is "any", then this will always succeed
if type == "any":
return True

# bool inherits from int, so ensure bools aren't reported as integers
if isinstance(instance, bool):
Expand Down
5 changes: 2 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,8 @@ def test_is_type_does_not_evade_bool_if_it_is_being_tested(self):
self.assertTrue(self.validator.is_type(True, "boolean"))
self.assertTrue(self.validator.is_type(True, "any"))

def test_is_type_raises_exception_for_unknown_type(self):
with self.assertRaises(UnknownType):
self.validator.is_type("foo", object())
def test_is_type_is_true_for_unknown_type(self):
self.assertTrue(self.validator.is_type("foo", "some_random_type"))


class TestRefResolver(TestCase):
Expand Down