You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Adding the @component to a component class that already derives from another component class with the @component decorator breaks the former's initialization if its __init__ method calls super() or super().__init__.
Error message
TypeError: super(type, obj): obj must be an instance or subtype of type
To Reproduce
Add the decorator to FaithfulnessEvaluator, which derives from LLMEvaluator.
The text was updated successfully, but these errors were encountered:
shadeMe
added
type:bug
Something isn't working
P2
Medium priority, add to the next sprint if no P1 available
2.x
Related to Haystack v2.0
labels
Jun 7, 2024
shadeMe
added
P1
High priority, add to the next sprint
and removed
P2
Medium priority, add to the next sprint if no P1 available
labels
Jun 14, 2024
This is most likely due to something similar to python-attrs/attrs#1038, the way we reconstruct any decorated component class with new_class would trigger the same problem with method rewriting.
Closest example to our case to reproduce:
fromtypesimportnew_classfromfunctoolsimportpartialdefcopyns(cls, ns):
"""Copy the namespace of the original class"""forkey, valindict(cls.__dict__).items():
ns[key] =valreturnnsclassMyMeta(type):
passclassBaseComponent:
pass# This is what the `@component` decorator would eventually doBaseComponent=new_class( # type:ignoreBaseComponent.__name__,
BaseComponent.__bases__,
{"metaclass": MyMeta},
partial(copyns, BaseComponent),
) # type:ignoreclassDerivedComponent(BaseComponent):
def__init__(self):
super().__init__()
DerivedComponent=new_class( # type:ignoreDerivedComponent.__name__,
DerivedComponent.__bases__,
{"metaclass": MyMeta},
partial(copyns, DerivedComponent),
) # type:ignoredc=DerivedComponent() # TypeError: super(type, obj): obj must be an instance or subtype of type
The workaround (that's also mentioned in the linked issue) is to "help" Python understand what's going on calling super() like this:
# ...classDerivedComponent(BaseComponent):
def__init__(self):
super(DerivedComponent, self).__init__()
# ...dc=DerivedComponent() # ok
Describe the bug
Adding the
@component
to a component class that already derives from another component class with the@component
decorator breaks the former's initialization if its__init__
method callssuper()
orsuper().__init__
.Error message
To Reproduce
Add the decorator to
FaithfulnessEvaluator
, which derives fromLLMEvaluator
.The text was updated successfully, but these errors were encountered: