Skip to content

msgspec.Struct cannot be used together with abc #806

@777michael777

Description

@777michael777

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions