From b21e672e80972869cda7f361f172a7e84b5735f2 Mon Sep 17 00:00:00 2001 From: Agil Mammadov Date: Thu, 14 May 2026 13:27:51 +0400 Subject: [PATCH] fix: handle explicit null values in Config.get --- nnote/config.py | 6 ++++-- tests/test_config.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nnote/config.py b/nnote/config.py index 01d0a4d..0d75375 100644 --- a/nnote/config.py +++ b/nnote/config.py @@ -44,14 +44,16 @@ def save(self) -> None: with self._path.open("w", encoding="utf-8") as f: yaml.dump(self._data, f, default_flow_style=False, allow_unicode=True) + _MISSING = object() + def get(self, *keys: str, default: Any = None) -> Any: """Retrieve a nested value by key path, returning default if missing.""" node = self._data for key in keys: if not isinstance(node, dict): return default - node = node.get(key, default) - if node is default: + node = node.get(key, self._MISSING) + if node is self._MISSING: return default return node diff --git a/tests/test_config.py b/tests/test_config.py index 2004d83..701c90c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -40,6 +40,14 @@ def test_get_missing_key_returns_default(tmp_path): assert config.get("missing", default="fallback") == "fallback" +def test_get_explicit_null_value(tmp_path): + cfg_file = tmp_path / "config.yaml" + cfg_file.write_text("key: null\n") + config = Config.load(cfg_file) + assert config.get("key") is None + assert config.get("key", default="fallback") is None + + def test_get_nested_key(tmp_path): cfg_file = tmp_path / "config.yaml" cfg_file.write_text("a:\n b: value\n")