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

@Requires decorator can be inherit #99

Open
pisua opened this issue Jun 28, 2018 · 3 comments
Open

@Requires decorator can be inherit #99

pisua opened this issue Jun 28, 2018 · 3 comments

Comments

@pisua
Copy link

pisua commented Jun 28, 2018

As property decorator that can be inherit from an super class. it cloud be interesting to inherit @requires decorator from a superclass to prevent to set it to the all child classes if they all have the same require instance to be injected unlike ipojo

@tcalmant tcalmant added this to the 0.8.0 milestone Jun 28, 2018
@tcalmant
Copy link
Owner

I have troubles replicating the issue, you can find my test bundle below.
It creates 3 components providing dummy services, a GrandParent class (not a factory) declaring a single @Requires, inherited by a Parent component factory with its own requirement, itself inherited by the Childcomponent factory.

Even when commenting the @Requires (toto) of Parent, the child still has the other two requirements injected.

Do you have a sample code to see what happens ?
Which version of iPOPO are you using ?

from pelix.ipopo.decorators import (
    ComponentFactory,
    Requires,
    Instantiate,
    Validate,
    Provides,
)
from pelix.framework import create_framework

@ComponentFactory()
@Provides("foo")
@Instantiate("foo")
class Foo:
    pass

@ComponentFactory()
@Provides("bar")
@Instantiate("bar")
class Bar:
    pass

@ComponentFactory()
@Provides("baz")
@Instantiate("baz")
class Baz:
    pass

@Requires("tutu", "baz")
class GrandParent:
    def __init__(self):
        self.tutu = None

@ComponentFactory()
@Requires("toto", "foo")
@Instantiate("parent")
class Parent(GrandParent):
    def __init__(self):
        super().__init__()
        self.toto = None

    @Validate
    def validate(self, ctx):
        print("Parent ## tutu=", self.tutu, "toto=", self.toto)

@ComponentFactory()
@Requires("titi", "bar")
@Instantiate("child")
class Child(Parent):
    def __init__(self):
        super().__init__()
        self.titi = None

    @Validate
    def validate(self, ctx):
        print(
            "Child ## tutu=", self.tutu, "toto=", self.toto, "titi=", self.titi
        )

Here is a sample output:

Child ## tutu= <check.Baz object at 0x00000209D2BB2940> toto= <check.Foo object at 0x00000209D2BED320> titi= <check.Bar object at 0x00000209D2BB2978>
Parent ## tutu= <check.Baz object at 0x00000209D2BB2940> toto= <check.Foo object at 0x00000209D2BED320>

@pisua
Copy link
Author

pisua commented Jun 29, 2018

I'll see to provide you asap the code sample.

@tcalmant tcalmant mentioned this issue Jul 16, 2018
3 tasks
@tcalmant
Copy link
Owner

No news on this issues and I couldn't reproduce it.
Moving it to milestone 0.8.1 waiting for more details.

@tcalmant tcalmant modified the milestones: 0.8.0, 0.8.1 Aug 19, 2018
@tcalmant tcalmant modified the milestones: 0.8.1, 0.8.2 Nov 17, 2018
@tcalmant tcalmant removed this from the 0.8.2 milestone May 7, 2020
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

2 participants