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

Cannot use param.Parameterized inheritance when inheriting alongside abstract classes #945

Open
DmitriyLeybel opened this issue Jun 18, 2024 · 0 comments

Comments

@DmitriyLeybel
Copy link

DmitriyLeybel commented Jun 18, 2024

ALL software version info

Python == 3.1x
Param == 2.1.0

Description of expected behavior and the observed behavior

In trying to inherit from param.Parameterized and an abstract class, an error is raised.

class BaseRAG(ABC):
    # add params as necessary for external use
    @abstractmethod
    def create_corpus(self):
        pass

class NewRAG(param.Parameterized, BaseRAG):
    def __init__(self):
        print('initd')

new_rag = NewRAG()

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

To get around it, this seems to work so far, although I'm not yet certain of the limitations:

class ParameterizedABCMeta(ABCMeta, type(param.Parameterized)):
    pass

class BaseRAG(param.Parameterized, metaclass=ParameterizedABCMeta):
    # add params as necessary for external use
    @abstractmethod
    def create_corpus(self):
        pass
    
    def tangible_method(self):
        print('something')


class NewRAG(BaseRAG):
    some_param = param.String('stringy')

    def __init__(self):
        print('initd')

    def create_corpus(self):
        pass

new_rag = NewRAG()

Similar mention here: https://discourse.holoviz.org/t/parameterized-abc/7257

But I thought I'd raise this as an issue for the library, as it seems somewhat notable that param.Parameterized does not work when combined with abstract classes.

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