-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Question
Hi all,
I have been working on trying to use the newly-exposed functionality for building metaclasses using StructMeta. Thanks to everyone involved for making this possible!
Very briefly, I want to create an abstract Struct subclass which requires that a few methods be implemented, as in the attached minimal example. I suspect that my issue here is operator error, and more specifically a lack of understanding of the metaclass -> class -> instance hierarchy.
I created a small script to demonstrate my issue:
abstract_issue.py
I based my implementation on the suggestion here.
In brief, the inheritance hierarchy seems to work fine, right up until I ask if an instance of ConcreteIntStruct is a subclass of IntegerStructBase, or if the type ConcreteIntStruct is a subclass of IntegerStructBase. I suspect my issue lies in not understanding the correct way to define abstract methods on a Struct using StructMeta and ABCMeta. The captured stdout of my minimal script is at the bottom.
If this is the simple operator error it feels like, I would be happy to clean up my example into a running script and write a paragraph to expand this section in the docs to make myself useful. If this is something more substantial, I am happy to help however possible.
The attached script produces the following output:
Msgspec ABC Issue Repro
Python version info:
3.13.7 (main, Aug 14 2025, 11:12:11) [Clang 17.0.0 (clang-1700.0.13.3)]
----------
Msgspec version info:
Name: msgspec
Version: 0.19.0+12.g651231e
----------
ConcreteIntStruct(val=1)
4
ConcreteIntStruct(val=4)
b'\x81\xa3val\x01'
ConcreteIntStruct(val=1)
Traceback (most recent call last):
File "/~path~", line 82, in <module>
main()
~~~~^^
File "~path~", line 77, in main
print(issubclass(ConcreteIntStruct, IntegerStructBase)) # Expect: True
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen abc>", line 123, in __subclasscheck__
AttributeError: type object 'IntegerStructBase' has no attribute '_abc_impl'