Skip to content
Open
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
8 changes: 8 additions & 0 deletions docs/source/structs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ at the end of the generated ``__init__`` method. It has the same semantics as th
This method may be useful for adding additional logic to the init (such as
custom validation).

.. important::

``__post_init__`` will *not* be called when using any of

- :func:`msgspec.structs.replace`,
- :func:`copy.replace`,
- :func:`copy.copy`,

In addition to in ``__init__``, the ``__post_init__`` hook is also called when:

- Decoding into a struct type (e.g. ``msgspec.json.decode(..., type=MyStruct)``)
Expand Down
3 changes: 2 additions & 1 deletion msgspec/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from typing import (
overload,
)

from typing_extensions import dataclass_transform, Buffer
from typing_extensions import dataclass_transform, Buffer, Self

from . import inspect, json, msgpack, structs, toml, yaml

Expand Down Expand Up @@ -118,6 +118,7 @@ class Struct(metaclass=StructMeta):
def __rich_repr__(
self,
) -> Iterable[Union[Any, Tuple[Any], Tuple[str, Any], Tuple[str, Any, Any]]]: ...
def __replace__(self, **changes: Any) -> Self: ...

def defstruct(
name: str,
Expand Down
Loading