Skip to content

Commit b219399

Browse files
Allow metaclasses that are subtype of EnumMeta
1 parent 7654e3a commit b219399

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

msgspec/_core.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,7 +4867,7 @@ typenode_collect_type(TypeNodeCollectState *state, PyObject *obj) {
48674867
) {
48684868
out = typenode_collect_struct(state, t);
48694869
}
4870-
else if (Py_TYPE(t) == state->mod->EnumMetaType) {
4870+
else if (PyType_IsSubtype(Py_TYPE(t), state->mod->EnumMetaType)) {
48714871
out = typenode_collect_enum(state, t);
48724872
}
48734873
else if (origin == (PyObject*)(&PyDict_Type)) {
@@ -13101,7 +13101,7 @@ mpack_encode_uncommon(EncoderState *self, PyTypeObject *type, PyObject *obj)
1310113101
else if (type == &Raw_Type) {
1310213102
return mpack_encode_raw(self, obj);
1310313103
}
13104-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
13104+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1310513105
return mpack_encode_enum(self, obj);
1310613106
}
1310713107
else if (type == (PyTypeObject *)(self->mod->DecimalType)) {
@@ -13774,7 +13774,7 @@ json_encode_dict_key_noinline(EncoderState *self, PyObject *obj) {
1377413774
else if (type == &PyFloat_Type) {
1377513775
return json_encode_float_as_str(self, obj);
1377613776
}
13777-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
13777+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1377813778
return json_encode_enum(self, obj, true);
1377913779
}
1378013780
else if (type == PyDateTimeAPI->DateTimeType) {
@@ -14178,7 +14178,7 @@ json_encode_uncommon(EncoderState *self, PyTypeObject *type, PyObject *obj) {
1417814178
else if (type == &Raw_Type) {
1417914179
return json_encode_raw(self, obj);
1418014180
}
14181-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
14181+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1418214182
return json_encode_enum(self, obj, false);
1418314183
}
1418414184
else if (PyType_IsSubtype(type, (PyTypeObject *)(self->mod->UUIDType))) {
@@ -19856,7 +19856,7 @@ to_builtins(ToBuiltinsState *self, PyObject *obj, bool is_key) {
1985619856
else if (Py_TYPE(type) == &StructMetaType) {
1985719857
return to_builtins_struct(self, obj, is_key);
1985819858
}
19859-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
19859+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1986019860
return to_builtins_enum(self, obj);
1986119861
}
1986219862
else if (is_key & PyUnicode_Check(obj)) {
@@ -21620,7 +21620,7 @@ convert(
2162021620
else if (pytype == (PyTypeObject *)self->mod->DecimalType) {
2162121621
return convert_decimal(self, obj, type, path);
2162221622
}
21623-
else if (Py_TYPE(pytype) == self->mod->EnumMetaType) {
21623+
else if (PyType_IsSubtype(Py_TYPE(pytype), self->mod->EnumMetaType)) {
2162421624
return convert_enum(self, obj, type, path);
2162521625
}
2162621626
else if (pytype == &Ext_Type) {

0 commit comments

Comments
 (0)