Skip to content
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

Use dir() instead of vars() in Referable.update_from() #338

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zrgt
Copy link
Contributor

@zrgt zrgt commented Nov 20, 2024

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.

Fixes #215

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.
@zrgt
Copy link
Contributor Author

zrgt commented Nov 20, 2024

The question here is: how should we handle properties that are not permitted to be set, such as SubmodelElementList.order_relevant?

In the previous solution, we simply set the attribute, even though it was not allowed. However, with the vars() and setattr() approach, an exception is raised, indicating either that no setter exists for the property or that setting it is explicitly forbidden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Referable.update_from() doesn't update parent namespace
1 participant