When calling .duplicate() on an HB Object (Room, etc) during __copy__(), the object's properties also get duplicated using the _duplicate_extension_attr method, called by the 'new' object, with the original object's properties passed in as the argument.
def __copy__(self):
new_r = Room(self.identifier, tuple(face.duplicate() for face in self._faces))
...
new_r._properties._duplicate_extension_attr(self._properties) #<---
return new_r
To duplicate the property object, within the _duplicate_extension_attr() the code then steps through the self._extension_attributes. However, this assumes that the property object names to duplicate already exist on the 'new' object (self) which is true for .energy and .radiance, but would not be true for any custom user-determined property objects other than .radiance and .energy. (Unless the parent classes have been modified / sub-classed and the new custom properties added ahead of time.)
def _duplicate_extension_attr(self, original_properties):
for atr in self._extension_attributes: # <------
var = getattr(original_properties, atr)
if not hasattr(var, 'duplicate'):
continue
try:
setattr(self, '_' + atr, var.duplicate(self.host))
except Exception as e:
...
By revising self._extension_attributes to original_properties._extension_attributes, the HB Object's duplicate() can now work for any properties object present on the HB-Obj. This allows for properties other than .radiance and .energy. to be added (assuming it passes the hasattr(..., ,'duplicate') guard).
Note that I think this will only result in a duplication of a user-added property object which is private ("_" prefix) and no duplication of any public getter? I'm not sure if that is ok or not? It seems that for user-added properties, having them always private is ok? Or if properties are supposed to be 'registering' with the host class somehow prior to any of this duplication code, this may be irrelevant, as then they would already be present on the self in the above example?
When calling
.duplicate()
on an HB Object (Room, etc) during__copy__()
, the object's properties also get duplicated using the _duplicate_extension_attr method, called by the 'new' object, with the original object's properties passed in as the argument.To duplicate the property object, within the _duplicate_extension_attr() the code then steps through the self._extension_attributes. However, this assumes that the property object names to duplicate already exist on the 'new' object (self) which is true for .energy and .radiance, but would not be true for any custom user-determined property objects other than .radiance and .energy. (Unless the parent classes have been modified / sub-classed and the new custom properties added ahead of time.)
By revising
self._extension_attributes
tooriginal_properties._extension_attributes
, the HB Object'sduplicate()
can now work for any properties object present on the HB-Obj. This allows for properties other than .radiance and .energy. to be added (assuming it passes thehasattr(..., ,'duplicate')
guard).Note that I think this will only result in a duplication of a user-added property object which is private ("_" prefix) and no duplication of any public getter? I'm not sure if that is ok or not? It seems that for user-added properties, having them always private is ok? Or if properties are supposed to be 'registering' with the host class somehow prior to any of this duplication code, this may be irrelevant, as then they would already be present on the self in the above example?