Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Unreleased
``initial_for_field`` instead.
- ``Field`` now mirrors pydantic's typed signature, so its keyword arguments are
type-checked and autocompleted.
- ``GoodConf.is_loaded`` allows to check whether the configuration got loaded.

7.0.0 (3 March 2026)
========================
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ First, create a ``conf.py`` file in your project's directory, next to
model_config = {"default_files": ["/etc/myproject/myproject.yaml", "myproject.yaml"]}

config = AppConfig()
config.is_loaded # False at this point, till `config.load()` is executed (see below)

Next, use the config in your ``settings.py`` file:

Expand Down
10 changes: 10 additions & 0 deletions goodconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def __repr__(self) -> str:


class GoodConf(BaseSettings):
_is_loaded: bool = False

def __init__(
self,
load: bool = False, # noqa: FBT001, FBT002 — documented public-API positional
Expand Down Expand Up @@ -262,10 +264,18 @@ def _load(
if config_file := _config_file or _init_config_file:
kwargs["_config_file"] = config_file
super().__init__(**kwargs)
self._is_loaded = True

def load(self, filename: str | None = None) -> None:
self._load(_config_file=filename)

@property
def is_loaded(self) -> bool:
try:
return self._is_loaded
except AttributeError:
return False

@classmethod
def get_initial(cls, **override: t.Any) -> dict[str, t.Any]:
return {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers = [
]
dependencies = [
"pydantic-settings>=2.13",
"pydantic>=2.7",
"pydantic>=2.12",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly this is required (I tried all versions below) since we seem to be running into a pydantic bug otherwise. That said if people need to use old pydantic they can pin goodconf (also this is not like the 1 -> 2 migration)

]
description = "Load configuration variables from a file or environment"
dynamic = ["version"]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_goodconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,17 @@ class SettingsClass:
False,
)
assert fileconfigsettingssource.get_field_value(None, "a") == (None, "", False) # type: ignore[arg-type]


def test_config_is_loaded() -> None:

class TestConf(GoodConf):
a: bool = False

cfg = TestConf()
assert cfg.is_loaded is False
cfg.load()
assert cfg.is_loaded is True

cfg = TestConf(load=True)
assert cfg.is_loaded is True
16 changes: 8 additions & 8 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading