+
Skip to content

Different behavior between generated model and dynamic loaded #119

Open
@AnNeub

Description

@AnNeub

I was working with a generated model so far. By refactoring my code to also work with dynamic loaded models I run into this issue.

The generator generates for features with upperBound != 1 something like this

    def __init__(self, *, name=None, messages=None):
        # if kwargs:
        #    raise AttributeError('unexpected arguments: {}'.format(kwargs))

        super().__init__(name=name, messages=messages)
 
        if name is not None:
            self.name = name

       if messages is not None:
           self.messages.extend(messages)   #<< relevant part

if you intialize a dynamic loaded class the initialization looks like this:

def new_init(self, *args, **kwargs):
        for name, value in kwargs.items():
            setattr(self, name, value)

which will not work if you provide a list as argument.

I change it to this to get it running.

def new_init(self, *args, **kwargs):
        for name, value in kwargs.items():
            feature = self.eClass.findEStructuralFeature(name)
            if feature:
                if feature.upperBound == 1:
                    setattr(self, name, value)
                else:
                    attr = getattr(self, name)
                    attr.extend(value)
            else:
                raise AttributeError(f'{self.eClass.name} has no attribute "{name}"')

I dont know if there are some drawbacks i have missed. From my point of view both implementation (generated and dynamic) shall behave similar to make it easier to switch between dynamic and generated.

Best regards,
Andreas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载