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
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions sdk/basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,25 @@ def update_from(self, other: "Referable", update_source: bool = False):
:param update_source: Update the source attribute with the other's source attribute. This is not propagated
recursively
"""
for name, var in vars(other).items():
# do not update the parent, namespace_element_sets or source (depending on update_source parameter)
if name in ("parent", "namespace_element_sets") or name == "source" and not update_source:
for name in dir(other):
# Skip private and protected attributes
if name.startswith('_'):
continue
if isinstance(var, NamespaceSet):

# Do not update 'parent', 'namespace_element_sets', or 'source' (depending on update_source parameter)
if name in ("parent", "namespace_element_sets") or (name == "source" and not update_source):
continue

# Skip methods
attr = getattr(other, name)
if callable(attr):
continue

if isinstance(attr, NamespaceSet):
# update the elements of the NameSpaceSet
vars(self)[name].update_nss_from(var)
getattr(self, name).update_nss_from(attr)
else:
vars(self)[name] = var # that variable is not a NameSpaceSet, so it isn't Referable
setattr(self, name, attr) # that variable is not a NameSpaceSet, so it isn't Referable

def commit(self) -> None:
"""
Expand Down Expand Up @@ -2068,11 +2078,11 @@ def update_nss_from(self, other: "NamespaceSet"):
elif isinstance(other_object, Qualifier):
backend, case_sensitive = self._backend["type"]
qualifier = backend[other_object.type if case_sensitive else other_object.type.upper()]
# qualifier.update_from(other_object, update_source=True) # TODO: What should happend here?
# qualifier.update_from(other_object, update_source=True) # TODO: What should happen here?
elif isinstance(other_object, Extension):
backend, case_sensitive = self._backend["name"]
extension = backend[other_object.name if case_sensitive else other_object.name.upper()]
# extension.update_from(other_object, update_source=True) # TODO: What should happend here?
# extension.update_from(other_object, update_source=True) # TODO: What should happen here?
else:
raise TypeError("Type not implemented")
except KeyError:
Expand Down
Loading