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
I am trying to create a Struct that is also an abstract class and run into the metaclass conflict.
Here's an example:
import msgspec
import abc
class Base(msgspec.Struct, metaclass=abc.ABCMeta):
member: int
@abc.abstractmethod
def method(self) -> None:
pass
class Subclass(Base):
pass
a = Subclass(7)
When executing above code, I get
Traceback (most recent call last):
File "x.py", line 5, in <module>
class Base(msgspec.Struct, metaclass=abc.ABCMeta):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Also tried with not using the metaclass, but inherit Base from abc.ABC directly, with the same result.
The text was updated successfully, but these errors were encountered:
That makes sense, since msgspec.Struct brings its own metaclass. No abstract classes for us.
Funny, I tried to do the same thing just days ago, but I didn't know how to pass both metaclass parameters and two base classes. Didn't occur to me ABC brings a metaclass too.
Description
I am trying to create a Struct that is also an abstract class and run into the metaclass conflict.
Here's an example:
When executing above code, I get
Also tried with not using the metaclass, but inherit Base from abc.ABC directly, with the same result.
The text was updated successfully, but these errors were encountered: