def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
if _debug:
Property._debug("WriteProperty(%s) %s %r arrayIndex=%r priority=%r direct=%r",
self.identifier, obj, value, arrayIndex, priority, direct
)
if (not direct):
# see if it must be provided
if not self.optional and value is None:
raise ValueError("%s value required" % (self.identifier,))
# see if it can be changed
if not self.mutable:
raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
#=================================
# THIS IS THE PART I'M QUESTIONNING
#if it's atomic assume correct datatype
if issubclass(self.datatype, Atomic):
if _debug: Property._debug(" - property is atomic, assumed correct type")
if isinstance(value, self.datatype):
if _debug: Property._debug(" - correct type")
elif arrayIndex is not None:
if not issubclass(self.datatype, Array):
raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
# check the array
arry = obj._values[self.identifier]
if arry is None:
raise RuntimeError("%s uninitialized array" % (self.identifier,))
# seems to be OK, let the array object take over
if _debug: Property._debug(" - forwarding to array")
arry[arrayIndex] = value
return
elif value is not None:
# coerce the value
value = self.datatype(value)
if _debug: Property._debug(" - coerced the value: %r", value)
# seems to be OK
obj._values[self.identifier] = value
I think we should restraint the value sent to a writeProperty fucntion to the datatype selected in the obejct.
Comparing the dataype of the object class.... without regard to the value sent to the function should be remove I think.