Michael Pasternak has posted comments on this change. Change subject: sdk: Save attributes to decorated object ......................................................................
Patch Set 3: (3 comments) http://gerrit.ovirt.org/#/c/30653/3/src/ovirtsdk/infrastructure/common.py File src/ovirtsdk/infrastructure/common.py: Line 34: attribute named "superclass". This name is required for backwards Line 35: compatibility with the CLI.""" Line 36: Line 37: def __init__(self, context): Line 38: self.__dict__[CONTEXT_ATTR] = context > It was already accessible: yes, but property != attribute and it read-only, __setattr__ addresses Immutablility of context. Line 39: Line 40: def __getattr__(self, name): Line 41: decorated = self.__dict__.get(DECORATED_ATTR) Line 42: if name == DECORATED_ATTR: Line 58: decorated = self.__dict__.get(DECORATED_ATTR) Line 59: if decorated is not None: Line 60: setattr(decorated, name, value) Line 61: else: Line 62: self.__dict__[name] = value > 1. Typos in attribute names are silently ignored by Python anyhow: 1. this is because python is a dynamic language, AttributeError would be thrown automatically if we was not overriding __setattr__, this is standard setattribute() behaviour i've mentioned, - now since we do override it, we should address this manually, (params is a bad example as it should be addressed by generateDS, we handling this area in common.Base.__setattr__) in our case it's permitted intentionally so we will be able creating sub-collections in brokers (which is obviously not a part of a type we're decorating) on the fly. but you can check the type of injected value, and if it's not a collection (only dynamic injection we permit) reject dynamic assignment by using standard attribute assignment that throws AttributeError. Line 63: Line 64: def __eq__(self, other): Line 65: return Comparator.compare(self, other) Line 66: Line 58: decorated = self.__dict__.get(DECORATED_ATTR) Line 59: if decorated is not None: Line 60: setattr(decorated, name, value) Line 61: else: Line 62: self.__dict__[name] = value > Regarding 2: Actually this can't be changed, because this class is used as not sure if i completely understand, but collections have: def __init__(self, datacenter , context): Base.__init__(self, context) self.parentclass = datacenter 'datacenter' is a parent class where they reside Line 63: Line 64: def __eq__(self, other): Line 65: return Comparator.compare(self, other) Line 66: -- To view, visit http://gerrit.ovirt.org/30653 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I4a4c5e08f844b250b585508c962fc0c38f9aad98 Gerrit-PatchSet: 3 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <[email protected]> Gerrit-Reviewer: Juan Hernandez <[email protected]> Gerrit-Reviewer: Michael Pasternak <[email protected]> Gerrit-Reviewer: Ravi Nori <[email protected]> Gerrit-Reviewer: [email protected] Gerrit-HasComments: Yes _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
