Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions msgspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MsgspecError,
Raw,
Struct,
StructMeta,
UnsetType,
UNSET,
NODEFAULT,
Expand Down
37 changes: 37 additions & 0 deletions msgspec/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,43 @@ class Struct:
self,
) -> Iterable[Union[Any, Tuple[Any], Tuple[str, Any], Tuple[str, Any, Any]]]: ...

class StructMeta(type):
__struct_fields__: ClassVar[Tuple[str, ...]]
__struct_defaults__: ClassVar[Tuple[Any, ...]]
__struct_encode_fields__: ClassVar[Tuple[str, ...]]
__match_args__: ClassVar[Tuple[str, ...]]
@property
def __signature__(self) -> inspect.Signature: ...
@property
def __struct_config__(self) -> structs.StructConfig: ...
def __new__(
cls,
name: str,
bases: Tuple[type, ...],
namespace: Dict[str, Any],
*,
tag_field: Optional[str] = None,
tag: Union[None, bool, str, int, Callable[[str], Union[str, int]]] = None,
rename: Union[
None,
Literal["lower", "upper", "camel", "pascal", "kebab"],
Callable[[str], Optional[str]],
Mapping[str, str],
] = None,
omit_defaults: bool = False,
forbid_unknown_fields: bool = False,
frozen: bool = False,
eq: bool = True,
order: bool = False,
kw_only: bool = False,
repr_omit_defaults: bool = False,
array_like: bool = False,
gc: bool = True,
weakref: bool = False,
dict: bool = False,
cache_hash: bool = False,
) -> StructMeta: ...

def defstruct(
name: str,
fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Any]]],
Expand Down
5 changes: 4 additions & 1 deletion msgspec/_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7146,7 +7146,7 @@ static PyTypeObject StructMetaType = {
.tp_name = "msgspec._core.StructMeta",
.tp_basicsize = sizeof(StructMetaObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_TYPE_SUBCLASS | Py_TPFLAGS_HAVE_GC | _Py_TPFLAGS_HAVE_VECTORCALL,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS | Py_TPFLAGS_HAVE_GC | _Py_TPFLAGS_HAVE_VECTORCALL,
.tp_new = StructMeta_new,
.tp_dealloc = (destructor) StructMeta_dealloc,
.tp_clear = (inquiry) StructMeta_clear,
Expand Down Expand Up @@ -22049,6 +22049,9 @@ PyInit__core(void)
Py_INCREF(&StructConfig_Type);
if (PyModule_AddObject(m, "StructConfig", (PyObject *)&StructConfig_Type) < 0)
return NULL;
Py_INCREF(&StructMetaType);
if (PyModule_AddObject(m, "StructMeta", (PyObject *)&StructMetaType) < 0)
return NULL;
Py_INCREF(&Ext_Type);
if (PyModule_AddObject(m, "Ext", (PyObject *)&Ext_Type) < 0)
return NULL;
Expand Down