Skip to content

Commit 95f1e00

Browse files
Allow metaclasses that are subtype of EnumMeta
1 parent 7a1143a commit 95f1e00

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/msgspec/_core.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,7 +5031,7 @@ typenode_collect_type(TypeNodeCollectState *state, PyObject *obj) {
50315031
) {
50325032
out = typenode_collect_struct(state, t);
50335033
}
5034-
else if (Py_TYPE(t) == state->mod->EnumMetaType) {
5034+
else if (PyType_IsSubtype(Py_TYPE(t), state->mod->EnumMetaType)) {
50355035
out = typenode_collect_enum(state, t);
50365036
}
50375037
else if (origin == (PyObject*)(&PyDict_Type)) {
@@ -13457,7 +13457,7 @@ mpack_encode_uncommon(EncoderState *self, PyTypeObject *type, PyObject *obj)
1345713457
else if (type == &Raw_Type) {
1345813458
return mpack_encode_raw(self, obj);
1345913459
}
13460-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
13460+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1346113461
return mpack_encode_enum(self, obj);
1346213462
}
1346313463
else if (type == (PyTypeObject *)(self->mod->DecimalType)) {
@@ -14134,7 +14134,7 @@ json_encode_dict_key_noinline(EncoderState *self, PyObject *obj) {
1413414134
else if (type == &PyFloat_Type) {
1413514135
return json_encode_float_as_str(self, obj);
1413614136
}
14137-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
14137+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1413814138
return json_encode_enum(self, obj, true);
1413914139
}
1414014140
else if (type == PyDateTimeAPI->DateTimeType) {
@@ -14561,7 +14561,7 @@ json_encode_uncommon(EncoderState *self, PyTypeObject *type, PyObject *obj) {
1456114561
else if (type == &Raw_Type) {
1456214562
return json_encode_raw(self, obj);
1456314563
}
14564-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
14564+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1456514565
return json_encode_enum(self, obj, false);
1456614566
}
1456714567
else if (PyType_IsSubtype(type, (PyTypeObject *)(self->mod->UUIDType))) {
@@ -20266,7 +20266,7 @@ to_builtins(ToBuiltinsState *self, PyObject *obj, bool is_key) {
2026620266
else if (ms_is_struct_type(type)) {
2026720267
return to_builtins_struct(self, obj, is_key);
2026820268
}
20269-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
20269+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
2027020270
return to_builtins_enum(self, obj);
2027120271
}
2027220272
else if (is_key & PyUnicode_Check(obj)) {
@@ -22035,7 +22035,7 @@ convert(
2203522035
else if (pytype == (PyTypeObject *)self->mod->DecimalType) {
2203622036
return convert_decimal(self, obj, type, path);
2203722037
}
22038-
else if (Py_TYPE(pytype) == self->mod->EnumMetaType) {
22038+
else if (PyType_IsSubtype(Py_TYPE(pytype), self->mod->EnumMetaType)) {
2203922039
return convert_enum(self, obj, type, path);
2204022040
}
2204122041
else if (pytype == &Ext_Type) {

0 commit comments

Comments
 (0)