Skip to content

Commit

Permalink
Update defstruct docs with mention of msgspec.field
Browse files Browse the repository at this point in the history
Also adds an example.
  • Loading branch information
alexei authored and jcrist committed Dec 4, 2023
1 parent 5593670 commit 3556137
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions msgspec/_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 3556137

Please sign in to comment.