CodeVetter · Repo Unpack · Data flow
pydantic/pydantic-settings
Inputs become dictionaries before final Pydantic validation. Constructor inputs and field aliases are normalized so source values can merge under compatible keys. Environment-shaped providers share decoding and nested expansion, whereas structured files parse into mappings first. The pipeline retains intermediate source dictionaries for dependent sources and optional diagnostics, then produces a validated model.
- _settings_init_sources resolves explicit constructor controls against model_config, with ENV_FILE_SENTINEL preserving the distinction between omitted dotenv configuration and an explicit None.
- InitSettingsSource matches constructor keys using configured case rules and alias preference, writes matched values under canonical preferred aliases, removes duplicate matches, and retains unmatched extras.
- EnvSettingsSource snapshots os.environ during initialization; parse_env_vars normalizes names, optionally drops empty strings, and marks configured null strings with EnvNoneType.
- Field acquisition searches extracted environment names in order; preparation decodes complex values and deep-merges delimiter-expanded nested values over a decoded top-level mapping.
- Structured file sources call ConfigFileSourceMixin._read_files, skip non-files, merge later file mappings over earlier ones shallowly or deeply, then feed the result through InitSettingsSource.
- CLI parsing produces a namespace or dictionary, resolves repeated values and selected subcommands, marks unselected subcommands as null, and converts the result into env_vars for inherited environment-style preparation.
- Before each source call, _settings_build_values supplies current_state and settings_sources_data; it records the source result and applies deep_update(source_state, state), giving previously merged sources priority.
- After merging, unchanged default-source values are removed, optional debug output is emitted, original constructor key names are restored, and BaseModel.__init__ validates the resulting mapping.