CodeVetter · Repo Unpack · Behavior traces
pydantic/pydantic
The source traces cover model definition and instantiation, JSON validation and serialization, and validated function invocation end-to-end. They also follow adapter initialization, JSON Schema export, plugin callbacks, and state restoration. Each sequence describes implementation order and material branches rather than an observed execution. Deferred schemas and optional return validation change when parts of these sequences run.
- Import flow: pydantic.__init__ imports version information → _ensure_pydantic_core_version checks compatibility → __getattr__ resolves a requested public symbol → import_module loads and caches exports.
- Model-definition flow: ModelMetaclass.__new__ → ConfigWrapper.for_model/inspect_namespace → DecoratorInfos.build → set_model_fields → complete_model_class → GenerateSchema.generate_schema/clean_schema → validator and serializer installation; defer_build substitutes mocks.
- Instantiation flow: BaseModel.__init__ → validate_python(data, self_instance=self) → SchemaValidator._validate → ModelValidator.validate_init → inner field validation → set_model_attrs → call_post_init.
- JSON round-trip flow: model_validate_json checks alias/name options → SchemaValidator.validate_json checks bytes → _validate_json parses through jiter and validates → model_dump_json calls SchemaSerializer.to_json → to_json_bytes/final warning check → bytes are decoded to str.
- TypeAdapter flow: __init__ captures appropriate function/caller namespaces → _init_core_attrs reuses existing schema objects or generates/cleans new ones → create_schema_validator and SchemaSerializer initialize → validate_python forwards per-call policy and partial-validation options.
- Function-call flow: validate_call → ValidateCallWrapper → _create_validators/GenerateSchema._call_schema → __call__ packages ArgsKwargs → Rust CallValidator validates arguments and invokes the function → optional return validator runs, awaiting coroutine results when necessary.
- JSON Schema flow: BaseModel.model_json_schema → model_json_schema constructs a generator and rebuilds a mocked core schema if necessary → GenerateJsonSchema.generate/generate_inner → definition cleanup/remapping → sorted dictionary; a used generator cannot be reused.
- State-restoration flow: __getstate__ emits instance fields, extras, fields-set, and defined private values → the caller's serialization mechanism carries that state → __setstate__ assigns it directly without invoking validation.