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

multiple inheritance requires to **kwargs in any case #33

Open
AnNeub opened this issue Mar 23, 2022 · 0 comments
Open

multiple inheritance requires to **kwargs in any case #33

AnNeub opened this issue Mar 23, 2022 · 0 comments

Comments

@AnNeub
Copy link

AnNeub commented Mar 23, 2022

If using multiple inheritance than the **kwargs need to be generated independent from eSuperTypes

{%- macro generate_class_init_args(c) -%}
    {% if c.eStructuralFeatures | list  %}, *, {% endif -%}
    {{ c.eStructuralFeatures | map(attribute='name') | map('re_sub', '$', '=None') | join(', ') }}
    {%- if c.eSuperTypes %}, **kwargs{% endif %}
{%- endmacro %}

{%- macro generate_super_init_args(c, user_module=False) -%}
    {%- if user_module and c.eStructuralFeatures -%}
    {{ c.eStructuralFeatures | map(attribute='name') | map('re_sub', '(.+)', '\g<0>= \g<0>') | join(', ') }}
    {%- endif %}
    {%- if c.eSuperTypes %}{{', ' if user_module and c.eStructuralFeatures else ''}}**kwargs{% endif %}
{%- endmacro %}

Following use case:

class A
  aattr1
  aattr2

class B 
 battr1
 battr2

class C(A,B)


C(aattr1=1, battr1=2)

A.__init__ looks like this def __init__(self, *, aattr1=None, aattr2=None)
This lead to the problem that A.__init__ is called with a keyword argument (battr1) which is not known by the init function.

BR
Andreas

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

No branches or pull requests

1 participant