holoviz/param

Cannot use param.Parameterized inheritance when inheriting alongside abstract classes

Opened this issue · 0 comments

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.