new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Pydantic · Concepts · all subjects

configuration propagation

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Configuration propagation for Pydantic models and dataclasses

When Pydantic models or dataclasses are used as field annotations, configuration is not propagated. Each model/dataclass has its own configuration boundary and uses only its own configuration.

Configuration propagation for stdlib types

When standard library dataclasses or TypedDict classes are used as field annotations, configuration is propagated from the parent model unless the type has its own configuration set. If a stdlib type has its own configuration, it uses that instead of the parent's configuration.

arbitrary_types_allowed config for stdlib dataclass with custom types

When a stdlib dataclass contains custom types and is used in a Pydantic model, you must set arbitrary_types_allowed=True in the model config to allow validation of those fields. This configuration propagates down to nested stdlib dataclasses.

arbitrary_types_allowed example with stdlib dataclass

import dataclasses from pydantic import BaseModel, ConfigDict from pydantic.errors import PydanticSchemaGenerationError class ArbitraryType: def __init__(self, value): self.value = value @dataclasses.dataclass class DC: a: ArbitraryType b: str my_dc = DC(a=ArbitraryType(value=3), b='qwe') # This fails without arbitrary_types_allowed: try: class Model(BaseModel): dc: DC other: str Model(dc=my_dc, other='other') except PydanticSchemaGenerationError as e: print(e.message) # Unable to generate pydantic-core schema for <class 'ArbitraryType'> # This works with arbitrary_types_allowed=True: class Model(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True) dc: DC other: str m = Model(dc=my_dc, other='other') print(repr(m)) # Model(dc=DC(a=ArbitraryType(value=3), b='qwe'), other='other') This example shows that arbitrary_types_allowed configuration propagates to nested stdlib dataclasses.

Give your agent this brain