-
Notifications
You must be signed in to change notification settings - Fork 40
Use dir() instead of vars() in Referable.update_from()
#338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
vars() only retrieves the instance's
__dict__—that is, the object's
attributes—but does not include
properties.
As a result, when you use vars(other),
you get the _id_short attribute instead
of the id_short property.
dir() iterates over all attributes and
properties of the object.
We skip callables and private attrs.
We use setattr() to set attributes and
properties, so setter funcs will be
used.
|
The question here is: how should we handle properties that are not permitted to be set, such as In the previous solution, we simply set the attribute, even though it was not allowed. However, with the |
|
My solution to this problem is: |
|
@zrgt or @s-heppner it would also be good if one of you changes the branch this PR is merged into to |
|
Ok then I will add that an error is thrown when an attribute that should not be set has been changed in the newer version of the object. |
|
After discussing this in the Dev-Team, we came to the following conclusion: The This behavior should also be noted in the method docstring. |
5b48a02 to
8a08d22
Compare
|
There seems to be a problem on the side of the eclipse foundation which is why the test is failing. |
|
Yes, there seems to be an outage of the Eclipse services at the moment. |
s-heppner
left a comment
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.
LGTM
…yx#338) Previously, we used `vars()` to iterate over all attributes of an object when updating it from another object (`Referable.update_from()`). However, `vars()` only retrieves the instance's `__dict__`, e.g. the object's attributes, but does not include properties. As a result, when you use `vars(other)`, you get the `_id_short` attribute instead of the `id_short` property. This made it impossible to utilize custom setter methods we developed for certain cases, e.g. when properties should be immutable. This now adapts the `Referable.update_from()` method to utilize `dir()` instead, which iterates over all attributes and properties of the object. We skip callables and private attributes. We use `setattr()` to set attributes and properties, so that the correct setter methods will be used. Furthermore, we now raise an error if an immutable property changed between the two versions of the object. Fixes eclipse-basyx#215 --------- Co-authored-by: Sercan Sahin <[email protected]>
…yx#338) Previously, we used `vars()` to iterate over all attributes of an object when updating it from another object (`Referable.update_from()`). However, `vars()` only retrieves the instance's `__dict__`, e.g. the object's attributes, but does not include properties. As a result, when you use `vars(other)`, you get the `_id_short` attribute instead of the `id_short` property. This made it impossible to utilize custom setter methods we developed for certain cases, e.g. when properties should be immutable. This now adapts the `Referable.update_from()` method to utilize `dir()` instead, which iterates over all attributes and properties of the object. We skip callables and private attributes. We use `setattr()` to set attributes and properties, so that the correct setter methods will be used. Furthermore, we now raise an error if an immutable property changed between the two versions of the object. Fixes eclipse-basyx#215 --------- Co-authored-by: Sercan Sahin <[email protected]>
Previously, we used
vars()to iterate over all attributes of an object when updating it from another object (Referable.update_from()).However,
vars()only retrieves the instance's__dict__, e.g. the object's attributes, but does not include properties. As a result, when you usevars(other), you get the_id_shortattribute instead of theid_shortproperty.This made it impossible to utilize custom setter methods we developed for certain cases, e.g. when properties should be immutable.
This now adapts the
Referable.update_from()method to utilizedir()instead, which iterates over all attributes and properties of the object. We skip callables and private attributes. We usesetattr()to set attributes and properties, so that the correct setter methods will be used.Furthermore, we now raise an error if an immutable property changed between the two versions of the object.
Fixes #215