Skip to content

Commit f13ac35

Browse files
committed
Don't floatify the instance in minimum/maximum messages.
1 parent 44b3570 commit f13ac35

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

jsonschema/_validators.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@ def minimum(validator, minimum, instance, schema):
7676
if not validator.is_type(instance, "number"):
7777
return
7878

79-
instance = float(instance)
8079
if schema.get("exclusiveMinimum", False):
81-
failed = instance <= minimum
80+
failed = float(instance) <= minimum
8281
cmp = "less than or equal to"
8382
else:
84-
failed = instance < minimum
83+
failed = float(instance) < minimum
8584
cmp = "less than"
8685

8786
if failed:
@@ -94,12 +93,11 @@ def maximum(validator, maximum, instance, schema):
9493
if not validator.is_type(instance, "number"):
9594
return
9695

97-
instance = float(instance)
9896
if schema.get("exclusiveMaximum", False):
99-
failed = instance >= maximum
97+
failed = float(instance) >= maximum
10098
cmp = "greater than or equal to"
10199
else:
102-
failed = instance > maximum
100+
failed = float(instance) > maximum
103101
cmp = "greater than"
104102

105103
if failed:

jsonschema/tests/test_validators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ def test_object_with_name_type_failure(self):
141141
message = self.message_for(instance=1, schema=schema)
142142
self.assertEqual(message, "1 is not of type %r" % (name,))
143143

144+
def test_minimum(self):
145+
message = self.message_for(instance=1, schema={"minimum" : 2})
146+
self.assertEqual(message, "1 is less than the minimum of 2")
147+
148+
def test_maximum(self):
149+
message = self.message_for(instance=1, schema={"maximum" : 0})
150+
self.assertEqual(message, "1 is greater than the maximum of 0")
151+
144152
def test_dependencies_failure_has_single_element_not_list(self):
145153
depend, on = "bar", "foo"
146154
schema = {u"dependencies" : {depend : on}}

0 commit comments

Comments
 (0)