Home / Function/ __post_init__() — fastapi Function Reference

__post_init__() — fastapi Function Reference

Architecture documentation for the __post_init__() function in v2.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  eba6f1ce_1c5f_6206_5659_da76ae8122e0["__post_init__()"]
  413233b4_cb0b_062e_c20b_4dfc7c774216["ModelField"]
  eba6f1ce_1c5f_6206_5659_da76ae8122e0 -->|defined in| 413233b4_cb0b_062e_c20b_4dfc7c774216
  1a429df6_f813_ef37_c0e6_58f50f452ff7["asdict()"]
  eba6f1ce_1c5f_6206_5659_da76ae8122e0 -->|calls| 1a429df6_f813_ef37_c0e6_58f50f452ff7
  style eba6f1ce_1c5f_6206_5659_da76ae8122e0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fastapi/_compat/v2.py lines 109–134

    def __post_init__(self) -> None:
        with warnings.catch_warnings():
            # Pydantic >= 2.12.0 warns about field specific metadata that is unused
            # (e.g. `TypeAdapter(Annotated[int, Field(alias='b')])`). In some cases, we
            # end up building the type adapter from a model field annotation so we
            # need to ignore the warning:
            if shared.PYDANTIC_VERSION_MINOR_TUPLE >= (2, 12):
                from pydantic.warnings import UnsupportedFieldAttributeWarning

                warnings.simplefilter(
                    "ignore", category=UnsupportedFieldAttributeWarning
                )
            # TODO: remove after setting the min Pydantic to v2.12.3
            # that adds asdict(), and use self.field_info.asdict() instead
            field_dict = asdict(self.field_info)
            annotated_args = (
                field_dict["annotation"],
                *field_dict["metadata"],
                # this FieldInfo needs to be created again so that it doesn't include
                # the old field info metadata and only the rest of the attributes
                Field(**field_dict["attributes"]),
            )
            self._type_adapter: TypeAdapter[Any] = TypeAdapter(
                Annotated[annotated_args],
                config=self.config,
            )

Domain

Subdomains

Calls

Frequently Asked Questions

What does __post_init__() do?
__post_init__() is a function in the fastapi codebase, defined in fastapi/_compat/v2.py.
Where is __post_init__() defined?
__post_init__() is defined in fastapi/_compat/v2.py at line 109.
What does __post_init__() call?
__post_init__() calls 1 function(s): asdict.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free