def append(self, object):
"""Add ``object`` to the ptype.container ``self``. Return the element's index.
When adding ``object`` to ``self``, none of the offsets are updated and
thus will need to be manually updated before committing to a provider.
"""
# if we're uninitialized, then create an empty value and try again
if self.value is None:
self.value = []
return self.append(object)
# if object is not an instance, then try to resolve it to one and try again
if not isinstance(object, generic):
res = self.new(object)
return self.append(res)
# assume that object is now a ptype instance
assert isinstance(object, generic), "container.append : {:s} : Tried to append unknown type to container : {:s}".format(self.instance(), object.__class__)
object.parent,object.source = self,None
current = len(self.value)
self.value.append(object if object.initializedQ() else object.a)
return current
评论列表
文章目录