summaryrefslogtreecommitdiff
path: root/src/zope/schema/_bootstrapfields.py
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2018-08-24 12:06:18 -0500
committerJason Madden <jamadden@gmail.com>2018-08-24 12:06:18 -0500
commitbab4c3104b82d4f4172180390bde5aec10a53e4e (patch)
tree0a7406788fdc45f80fc63a4dd1044c172f92104f /src/zope/schema/_bootstrapfields.py
parent845376502821b0ad4a08f5a3691b06cd49f1c9a3 (diff)
downloadzope-schema-issue16.tar.gz
Raise proper validation errors from Int and Float as well as Decimal.issue16
Fix the doctests that pointed out this should be done.
Diffstat (limited to 'src/zope/schema/_bootstrapfields.py')
-rw-r--r--src/zope/schema/_bootstrapfields.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/zope/schema/_bootstrapfields.py b/src/zope/schema/_bootstrapfields.py
index c96c7d8..6501310 100644
--- a/src/zope/schema/_bootstrapfields.py
+++ b/src/zope/schema/_bootstrapfields.py
@@ -19,6 +19,7 @@ from zope.interface import Attribute
from zope.interface import providedBy
from zope.interface import implementer
+from zope.schema._bootstrapinterfaces import ValidationError
from zope.schema._bootstrapinterfaces import ConstraintNotSatisfied
from zope.schema._bootstrapinterfaces import IContextAwareDefaultFactory
from zope.schema._bootstrapinterfaces import IFromUnicode
@@ -440,6 +441,9 @@ class Bool(Field):
self.validate(v)
return v
+class InvalidIntLiteral(ValueError, ValidationError):
+ """Invalid int literal."""
+
@implementer(IFromUnicode)
class Int(Orderable, Field):
@@ -458,8 +462,11 @@ class Int(Orderable, Field):
>>> f.fromUnicode("125.6") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
- ValueError: invalid literal for int(): 125.6
+ InvalidIntLiteral: invalid literal for int(): 125.6
"""
- v = int(str)
+ try:
+ v = int(str)
+ except ValueError as v:
+ raise InvalidIntLiteral(*v.args).with_field_and_value(self, str)
self.validate(v)
return v