Skip to content

Commit 0196026

Browse files
committed
properties: include <class>.<propertyname> everytime we are raising a ValueError
1 parent 521c1fe commit 0196026

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

kivy/properties.pyx

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ cdef class Property:
183183
'''
184184
if x is None:
185185
if not obj.__storage[self._name]['allownone']:
186-
raise ValueError('None is not allowed')
186+
raise ValueError('None is not allowed for %s.%s' % (
187+
obj.__class__.__name__,
188+
self.name))
187189
else:
188190
return True
189191

@@ -206,7 +208,7 @@ cdef class Property:
206208
cdef class NumericProperty(Property):
207209
'''Property that represents a numeric value
208210
209-
The NumericProperty accepts only int or float.
211+
The NumericProperty accept only int or float.
210212
211213
>>> Widget.x = 42
212214
>>> print Widget.x
@@ -217,13 +219,15 @@ cdef class NumericProperty(Property):
217219
File "properties.pyx", line 93, in kivy.properties.Property.__set__
218220
File "properties.pyx", line 111, in kivy.properties.Property.set
219221
File "properties.pyx", line 159, in kivy.properties.NumericProperty.check
220-
ValueError: NumericProperty accepts only int/float
222+
ValueError: NumericProperty accept only int/float
221223
'''
222224
cdef check(self, obj, value):
223225
if Property.check(self, obj, value):
224226
return True
225227
if type(value) not in (int, float):
226-
raise ValueError('NumericProperty<%s> accepts only int/float' % self.name)
228+
raise ValueError('%s.%s accept only int/float' % (
229+
obj.__class__.__name__,
230+
self.name))
227231

228232

229233
cdef class StringProperty(Property):
@@ -235,8 +239,9 @@ cdef class StringProperty(Property):
235239
if Property.check(self, obj, value):
236240
return True
237241
if not isinstance(value, basestring):
238-
raise ValueError('StringProperty<%s> accepts only str/unicode' %
239-
self.name)
242+
raise ValueError('%s.%s accept only str/unicode' % (
243+
obj.__class__.__name__,
244+
self.name))
240245

241246
cdef inline void observable_list_dispatch(object self):
242247
cdef Property prop = self.prop
@@ -320,8 +325,9 @@ cdef class ListProperty(Property):
320325
if Property.check(self, obj, value):
321326
return True
322327
if type(value) is not ObservableList:
323-
raise ValueError('ListProperty<%s> accepts only ObservableList'
324-
' (should never happen.)' % self.name)
328+
raise ValueError('%s.%s accept only ObservableList' % (
329+
obj.__class__.__name__,
330+
self.name))
325331

326332
cpdef set(self, obj, value):
327333
value = ObservableList(self, obj, value)
@@ -388,8 +394,9 @@ cdef class DictProperty(Property):
388394
if Property.check(self, obj, value):
389395
return True
390396
if type(value) is not ObservableDict:
391-
raise ValueError('DictProperty<%s> accepts only ObservableDict'
392-
' (should never happen.)' % self.name)
397+
raise ValueError('%s.%s accept only ObservableDict' % (
398+
obj.__class__.__name__,
399+
self.name))
393400

394401
cpdef set(self, obj, value):
395402
value = ObservableDict(self, obj, value)
@@ -407,8 +414,9 @@ cdef class ObjectProperty(Property):
407414
if Property.check(self, obj, value):
408415
return True
409416
if not isinstance(value, object):
410-
raise ValueError('ObjectProperty<%s> accepts only Python objects' %
411-
self.name)
417+
raise ValueError('%s.%s accept only Python object' % (
418+
obj.__class__.__name__,
419+
self.name))
412420

413421
cdef class BooleanProperty(Property):
414422
'''Property that represents only boolean
@@ -417,7 +425,9 @@ cdef class BooleanProperty(Property):
417425
if Property.check(self, obj, value):
418426
return True
419427
if not isinstance(value, object):
420-
raise ValueError('BooleanProperty<%s> accepts only bool' % self.name)
428+
raise ValueError('%s.%s accept only bool' % (
429+
obj.__class__.__name__,
430+
self.name))
421431

422432
cdef class BoundedNumericProperty(Property):
423433
'''Property that represents a numeric value within a minimum bound and/or
@@ -469,13 +479,15 @@ cdef class BoundedNumericProperty(Property):
469479
if s['use_min']:
470480
_min = s['min']
471481
if value < _min:
472-
raise ValueError('BoundedNumericProperty<%s> is below the '
473-
'minimum bound (%d)' % (self.name, _min))
482+
raise ValueError('%s.%s is below the minimum bound (%d)' % (
483+
obj.__class__.__name__,
484+
self.name, _min))
474485
if s['use_max']:
475486
_max = s['max']
476487
if value > _max:
477-
raise ValueError('BoundedNumericProperty<%s> is above the '
478-
'maximum bound (%d)' % (self.name, _max))
488+
raise ValueError('%s.%s is above the maximum bound (%d)' % (
489+
obj.__class__.__name__,
490+
self.name, _max))
479491
return True
480492

481493
property bounds:
@@ -518,8 +530,10 @@ cdef class OptionProperty(Property):
518530
return True
519531
valid_options = obj.__storage[self._name]['options']
520532
if value not in valid_options:
521-
raise ValueError('OptionProperty<%s> have an invalid option %r. '
522-
'Must be one of: %s' % (self.name,
533+
raise ValueError('%s.%s is set to an invalid option %r. '
534+
'Must be one of: %s' % (
535+
obj.__class__.__name__,
536+
self.name,
523537
value, valid_options))
524538

525539
property options:
@@ -571,14 +585,16 @@ cdef class ReferenceListProperty(Property):
571585

572586
cdef convert(self, obj, value):
573587
if not isinstance(value, (list, tuple)):
574-
raise ValueError('ReferenceListProperty<%s> must be a list or a '
575-
'tuple' % self.name)
588+
raise ValueError('%s.%s must be a list or a tuple' % (
589+
obj.__class__.__name__,
590+
self.name))
576591
return list(value)
577592

578593
cdef check(self, obj, value):
579594
if len(value) != len(obj.__storage[self._name]['properties']):
580-
raise ValueError('ReferenceListProperty<%s> value length is '
581-
'immutable' % self.name)
595+
raise ValueError('%s.%s value length is immutable' % (
596+
obj.__class__.__name__,
597+
self.name))
582598

583599
cpdef set(self, obj, _value):
584600
cdef int idx

0 commit comments

Comments
 (0)