diff --git a/msgspec/_core.c b/msgspec/_core.c index b1b8fa80..6d968890 100644 --- a/msgspec/_core.c +++ b/msgspec/_core.c @@ -6209,8 +6209,9 @@ PyDoc_STRVAR(msgspec_defstruct__doc__, " The name of the new Struct class.\n" "fields : iterable\n" " An iterable of fields in the new class. Elements may be either ``name``,\n" -" tuples of ``(name, type)``, or ``(name, type, default)``. Fields without\n" -" a specified type will default to ``typing.Any``.\n" +" tuples of ``(name, type)``, ``(name, type, default)``, or \n" +" ``(name, type, msgspec.field)``. Fields without a specified type will \n" +" default to ``typing.Any``.\n" "bases : tuple, optional\n" " A tuple of any Struct base classes to use when defining the new class.\n" "module : str, optional\n" @@ -6223,6 +6224,20 @@ PyDoc_STRVAR(msgspec_defstruct__doc__, " Additional Struct configuration options. See the ``Struct`` docs for more\n" " information.\n" "\n" +"Examples\n" +"--------\n" +">>> from msgspec import defstruct, field\n" +">>> User = defstruct(\n" +"... 'User',\n" +"... [\n" +"... ('name', str),\n" +"... ('email', str | None, None),\n" +"... ('groups', set[str], field(default_factory=set)),\n" +"... ],\n" +"... )\n" +">>> User('alice')\n" +"User(name='alice', email=None, groups=set())\n" +"\n" "See Also\n" "--------\n" "Struct"