From 44ae99ebd2613cef64914b47af10acb68d464c70 Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sun, 22 Feb 2026 00:47:18 -0700 Subject: [PATCH 1/3] build(deps): specify `typing_extensions` package in range from `v4.13` to `< v5.0` --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 60321cc..96652b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ authors = [ maintainers = [{ name = "codejedi365", email = "codejedi365+flatdictpy@gmail.com" }] dependencies = [ "Deprecated ~= 1.3", + "typing_extensions >= 4.13, < 5.0", ] From 567a4eacbf782fbef4acbf188120f415edec8086 Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sun, 22 Feb 2026 00:13:52 -0700 Subject: [PATCH 2/3] test(FlatDict): add test of `update()` method when passed another FlatDict --- tests/flatdict_test.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/flatdict_test.py b/tests/flatdict_test.py index 73e9e8d..1b3407b 100644 --- a/tests/flatdict_test.py +++ b/tests/flatdict_test.py @@ -371,6 +371,45 @@ def test_flatdict_update_empty(request: pytest.FixtureRequest): assert flat_dict["b.c"] == [2] +def test_flatdict_update_from_flatdict(request: pytest.FixtureRequest): + if not str(request.config.getoption("-k")): + depends(request, [test_flatdict_dunder_getitem.__name__], scope="module") + + base_data: dict[str, Any] = {"a": 1, "b": {"c": 2, "d": 3}} + base_flat_dict = FlatDict(base_data, delimiter=".") + + # Test merging a FlatDict with overlapping and new keys into another FlatDict + update_data: dict[str, Any] = {"b": {"d": 99, "e": 4}, "f": 5} + update_flat_dict = FlatDict(update_data, delimiter=".") + base_flat_dict.update(update_flat_dict) + + # Original key unchanged + assert base_data["a"] == base_flat_dict["a"] + # Nested key preserved from base where not overwritten + assert base_data["b"]["c"] == base_flat_dict["b.c"] + # Overlapping nested key overwritten by update + assert update_data["b"]["d"] == base_flat_dict["b.d"] + # New nested key added from update + assert update_data["b"]["e"] == base_flat_dict["b.e"] + # New top-level key added from update + assert update_data["f"] == base_flat_dict["f"] + + # Test overwriting a top-level key with a FlatDict using a different delimiter + base_flat_dict2 = FlatDict({"x": 10, "y": {"z": 20}}, delimiter=".") + update_flat_dict2 = FlatDict({"y": {"z": 99, "w": 30}}, delimiter=".") + base_flat_dict2.update(update_flat_dict2) + + assert 10 == base_flat_dict2["x"] + assert 99 == base_flat_dict2["y.z"] + assert 30 == base_flat_dict2["y.w"] + + # Test that updating with an empty FlatDict does not change the content + base_flat_dict3 = FlatDict({"a": 1, "b": {"c": 2}}, delimiter=".") + base_flat_dict3.update(FlatDict()) + assert 1 == base_flat_dict3["a"] + assert {"c": 2} == base_flat_dict3["b"] + + @pytest.mark.order("third") @pytest.mark.dependency def test_flatdict_values(request: pytest.FixtureRequest): From 9d6d4a3ac7b46939355db47e10a30790d86b48f8 Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sun, 22 Feb 2026 00:00:09 -0700 Subject: [PATCH 3/3] fix(FlatDict): enable `update()` from another FlatDict object --- src/cj365/flatdict/flat_dict.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cj365/flatdict/flat_dict.py b/src/cj365/flatdict/flat_dict.py index c28f58f..af5fc5d 100644 --- a/src/cj365/flatdict/flat_dict.py +++ b/src/cj365/flatdict/flat_dict.py @@ -272,7 +272,10 @@ def update(self, arg: Any = None, /, **kwargs: Any) -> None: """ params = {**kwargs} if arg is not None: - if hasattr(arg, "keys") and hasattr(arg, "__getitem__"): + if isinstance(arg, self.__class__): + params.update(arg.inflate()) + + elif hasattr(arg, "keys") and hasattr(arg, "__getitem__"): params.update( { k: arg[k] @@ -282,6 +285,9 @@ def update(self, arg: Any = None, /, **kwargs: Any) -> None: else: params.update({k: v for k, v in arg}) + if not params: + return + flattened_params = self.flatten(params, self.delimiter) if matching_meta_keys := flattened_params.keys() & set(self.meta_keys):