This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proposed solution for part of the issue #157.
This commit alters the metaclass "MetaStruct". Now it will consider the existance of a `__ordered__` attribute of the base classes being used and also will evaluate three new `private` class attributes: - remove_attributes; - rename_attributes; - insert_before. With these three new attributes now we can have control of class attributes modifications while inheriting from another class (based on GenericStruct or GenericMessage). Usage: ```python class MyClassA(GenericStruct): attr_0 = UBInt8() attr_a = UBInt16() attr_z = UBInt8() attr_c = UBInt8() class MyClassB(MyClassA): attr_c = UBInt32() # This will update the attr_c from parent class attr_d = UBInt8() # This will add a new attribute positioned befor attr_a # according to the defined below attr_e = 8 # This will add a new attribute at the end of the list. _remove_attributes = ['attr_z'] _rename_attributes = [('attr_0', 'attr_new_name')] _insert_attributes_before = {'attr_d': 'attr_a'} ``` The resulting dictionary of 'MyClassB' will be: ```python OrderedDict([('attr_new_name', pyof.foundation.basic_types.UBInt8), ('attr_d', pyof.foundation.basic_types.UBInt8), ('attr_a', pyof.foundation.basic_types.UBInt16), ('attr_c', pyof.foundation.basic_types.UBInt32), ('attr_e', int)]) ``` Signed-off-by: Diego Rabatone Oliveira <[email protected]>
- Loading branch information
cd39026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create a class to manage the ordered attribute updates as well as
Enum
updates. Thus, the metaclass won't excessive responsibility and it will be easier to test.