Skip to content

Add setter-functions for object attributes that consist of NamespaceSets #65

Open

Description

@s-heppner

When instantiating an AssetAdministrationShell-object, we hand over ConceptDictionarys in any kind of Iterable (See here)

def __init__(self,
                 ...
                 concept_dictionary: Iterable[concept.ConceptDictionary] = (),
                 ...):

However, internally, we create a NamespaceSet containing these ConceptDictionarys in order to be able to resolve them later:

self.concept_dictionary: base.NamespaceSet[concept.ConceptDictionary] = \
            base.NamespaceSet(self, concept_dictionary)

Now, if a user were to only look at the initialization parameters, and wanted to add a ConceptDictionary later, after initalization, they could theoretically assume, they could set it like this:

my_aas.concept_dictionary = [my_concept_dictionary]

This would have terrible results when iterating over ObjectStores containing these objects, since suddenly, we'd get the (not very helpful) error:

AttributeError: 'list' object has no attribute 'update_nss_from' 

This obviously points nowhere in the right direction.

I have the suspicion, that this is not the only time, where such a problem may arise. How can we restrrict the user from making such a mistake in the first place? Should we write getter and setter functions for these kinds of attributes? On the other hand, maybe this is something to be checked by the ObjectStore, when adding an item to it?

Activity

  1. added
    enhancementEnhancement of an existing feature
    questionFurther information is requested
    on Apr 18, 2023
  2. jkhsjdhjs commented on Apr 18, 2023

    @jkhsjdhjs
    Contributor

    A typechecker will catch the error of assigning a list where a NamespaceSet is expected. So if the user uses a typechecker (which they should), this won't be an issue. If the user on the other hand assigns a different NamespaceSet to the attribute, I think they should know how to use a NamespaceSet correctly, which is described by the docstring.

    We could provide a setter function for the attributes where a NamespaceSet is expected just for usability reasons (I've done that for the OrderedNamespaceSet of SubmodelElementList for example).

  3. s-heppner commented on Apr 18, 2023

    @s-heppner
    MemberAuthor

    You're right, a type-checker would have caught that.

    Nevertheless, I'm all for your suggestion of writing setter-functions on attributes where a NamespaceSet is expected. I'll adapt the issue accordingly.

  4. changed the title [-]Confusion when adding `ConceptDescription` after instantiation of `AssetAdministrationShell`[/-] [+]Add setter-functions for object attributes that consist of `NamespaceSet`s[/+] on Apr 18, 2023
  5. added
    sdkSomething to do with the `sdk` package
    on Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancement of an existing featuresdkSomething to do with the `sdk` package

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions