Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions msgspec/_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6043,16 +6043,11 @@ StructMeta_new_inner(
/* Fill in struct offsets */
if (structmeta_construct_offsets(&info, cls) < 0) goto cleanup;

/* Cache access to __post_init__ (if defined).
* XXX: When StructMeta is defined, the module hasn't finished initializing
* yet so `mod` will be NULL here. */
if (mod != NULL) {
cls->post_init = PyObject_GetAttr((PyObject *)cls, mod->str___post_init__);
/* Cache access to __post_init__ (if defined). */
cls->post_init = PyObject_GetAttr((PyObject *)cls, mod->str___post_init__);
if (cls->post_init == NULL) {
PyErr_Clear();
}
else {
cls->post_init = NULL;
}

cls->nkwonly = info.nkwonly;
cls->n_trailing_defaults = info.n_trailing_defaults;
Expand Down Expand Up @@ -21067,17 +21062,6 @@ PyInit__core(void)
if (PyModule_AddObject(m, "UNSET", UNSET) < 0)
return NULL;

/* Initialize the Struct Type */
st->StructType = PyObject_CallFunction(
(PyObject *)&StructMetaType, "s(O){ssss}", "Struct", &StructMixinType,
"__module__", "msgspec", "__doc__", Struct__doc__
);
if (st->StructType == NULL)
return NULL;
Py_INCREF(st->StructType);
if (PyModule_AddObject(m, "Struct", st->StructType) < 0)
return NULL;

/* Initialize the exceptions. */
st->MsgspecError = PyErr_NewExceptionWithDoc(
"msgspec.MsgspecError",
Expand Down Expand Up @@ -21245,5 +21229,15 @@ PyInit__core(void)
CACHED_STRING(str_int, "int");
CACHED_STRING(str_is_safe, "is_safe");

/* Initialize the Struct Type */
PyState_AddModule(m, &msgspecmodule);
st->StructType = PyObject_CallFunction(
(PyObject *)&StructMetaType, "s(O){ssss}", "Struct", &StructMixinType,
"__module__", "msgspec", "__doc__", Struct__doc__
);
if (st->StructType == NULL) return NULL;
Py_INCREF(st->StructType);
if (PyModule_AddObject(m, "Struct", st->StructType) < 0) return NULL;

return m;
}