You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I should note that if one provides a Traversable, it does currently work, indicating the subset of Path functionality used by pydantic-settings is within the Traversable subset of Path.
In the example below, I pass a Traversable, and I have verified in a test that it does indeed load the packaged resource file just fine.
Motivation
A somewhat useful pattern is to package a default configuration file inside a Python package. For example:
Currently I bypass this by simply using typing.cast to cast Traversable into Path. This is a bit brittle as there's no guarantee pydantic_settings won't eventually start using something Traversable doesn't support, but at least today it does indeed work.
There are issues with the typing for the file options for
SettingsConfigDict
:PathType | None
despite documentation indicating they accept lists (which indeed they do).pydantic-settings/pydantic_settings/main.py
Lines 43 to 46 in bcbfd17
The documentation indicates this at: https://docs.pydantic.dev/latest/concepts/pydantic_settings/#other-settings-source
PathType
could, but does not not includeimportlib.resources.abc.Traversable
:pydantic-settings/pydantic_settings/sources.py
Line 87 in bcbfd17
I should note that if one provides a
Traversable
, it does currently work, indicating the subset ofPath
functionality used bypydantic-settings
is within theTraversable
subset ofPath
.In the example below, I pass a
Traversable
, and I have verified in a test that it does indeed load the packaged resource file just fine.Motivation
A somewhat useful pattern is to package a default configuration file inside a Python package. For example:
And then have in
src/foobar/foobar.defaults.toml
:This currently works. However, it will not type-check.
The text was updated successfully, but these errors were encountered: