fix setting None, NotLoaded and NotAvailable values on fields

This commit is contained in:
Romain Bignon 2012-03-26 22:56:10 +02:00
commit 4ea7872ba4

View file

@ -313,6 +313,7 @@ class CapBaseObject(object):
except KeyError: except KeyError:
object.__setattr__(self, name, value) object.__setattr__(self, name, value)
else: else:
if value not in (NotLoaded, NotAvailable, None):
try: try:
# Try to convert value to the wanted one. # Try to convert value to the wanted one.
value = attr.convert(value) value = attr.convert(value)
@ -321,6 +322,7 @@ class CapBaseObject(object):
# match the wanted following types, so we'll # match the wanted following types, so we'll
# raise ValueError. # raise ValueError.
pass pass
if not isinstance(value, attr.types) and \ if not isinstance(value, attr.types) and \
value is not NotLoaded and \ value is not NotLoaded and \
value is not NotAvailable and \ value is not NotAvailable and \