Skip to content

Commit 1be9289

Browse files
Allow metaclasses that are subtype of EnumMeta
1 parent ceb5775 commit 1be9289

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
@@ -4948,7 +4948,7 @@ typenode_collect_type(TypeNodeCollectState *state, PyObject *obj) {
49484948
) {
49494949
out = typenode_collect_struct(state, t);
49504950
}
4951-
else if (Py_TYPE(t) == state->mod->EnumMetaType) {
4951+
else if (PyType_IsSubtype(Py_TYPE(t), state->mod->EnumMetaType)) {
49524952
out = typenode_collect_enum(state, t);
49534953
}
49544954
else if (origin == (PyObject*)(&PyDict_Type)) {
@@ -13310,7 +13310,7 @@ mpack_encode_uncommon(EncoderState *self, PyTypeObject *type, PyObject *obj)
1331013310
else if (type == &Raw_Type) {
1331113311
return mpack_encode_raw(self, obj);
1331213312
}
13313-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
13313+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1331413314
return mpack_encode_enum(self, obj);
1331513315
}
1331613316
else if (type == (PyTypeObject *)(self->mod->DecimalType)) {
@@ -13987,7 +13987,7 @@ json_encode_dict_key_noinline(EncoderState *self, PyObject *obj) {
1398713987
else if (type == &PyFloat_Type) {
1398813988
return json_encode_float_as_str(self, obj);
1398913989
}
13990-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
13990+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1399113991
return json_encode_enum(self, obj, true);
1399213992
}
1399313993
else if (type == PyDateTimeAPI->DateTimeType) {
@@ -14414,7 +14414,7 @@ json_encode_uncommon(EncoderState *self, PyTypeObject *type, PyObject *obj) {
1441414414
else if (type == &Raw_Type) {
1441514415
return json_encode_raw(self, obj);
1441614416
}
14417-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
14417+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
1441814418
return json_encode_enum(self, obj, false);
1441914419
}
1442014420
else if (PyType_IsSubtype(type, (PyTypeObject *)(self->mod->UUIDType))) {
@@ -20119,7 +20119,7 @@ to_builtins(ToBuiltinsState *self, PyObject *obj, bool is_key) {
2011920119
else if (PyType_IsSubtype(Py_TYPE(type), &StructMetaType)) {
2012020120
return to_builtins_struct(self, obj, is_key);
2012120121
}
20122-
else if (Py_TYPE(type) == self->mod->EnumMetaType) {
20122+
else if (PyType_IsSubtype(Py_TYPE(type), self->mod->EnumMetaType)) {
2012320123
return to_builtins_enum(self, obj);
2012420124
}
2012520125
else if (is_key & PyUnicode_Check(obj)) {
@@ -21888,7 +21888,7 @@ convert(
2188821888
else if (pytype == (PyTypeObject *)self->mod->DecimalType) {
2188921889
return convert_decimal(self, obj, type, path);
2189021890
}
21891-
else if (Py_TYPE(pytype) == self->mod->EnumMetaType) {
21891+
else if (PyType_IsSubtype(Py_TYPE(pytype), self->mod->EnumMetaType)) {
2189221892
return convert_enum(self, obj, type, path);
2189321893
}
2189421894
else if (pytype == &Ext_Type) {

0 commit comments

Comments
 (0)