Add type validation on complex type attributes assignment

This commit is contained in:
Christophe de Vienne
2011-10-28 12:24:15 +02:00
parent c2354eff9f
commit 45016290b4

View File

@@ -76,6 +76,11 @@ class wsattr(object):
return getattr(instance, '_' + self.key, Unset)
def __set__(self, instance, value):
if value is not None and not isinstance(value, self.datatype):
raise ValueError(
"Wrong type for attribute %s. Expected '%s', got '%s'" % (
self.key, self.datatype, type(value)
))
setattr(instance, '_' + self.key, value)
def __delete__(self, instance):