From a61fab1313ff88daf8e4182f7101322f5c65bb4c Mon Sep 17 00:00:00 2001 From: Chris Griffith Date: Thu, 16 Jan 2025 12:53:08 -0600 Subject: [PATCH 1/2] =?UTF-8?q?*=20Fixing=20#288=20default=20get=20value?= =?UTF-8?q?=20error=20when=20using=20box=5Fdots=20(thanks=20to=20S=C3=A9ba?= =?UTF-8?q?stien=20Weber)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/box.py | 6 +++--- test/test_box.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/box/box.py b/box/box.py index 937ba0e..8be6738 100644 --- a/box/box.py +++ b/box/box.py @@ -414,6 +414,8 @@ def __contains__(self, item): except BoxError: return False else: + if not super().__contains__(first_item): + return False it = self[first_item] return isinstance(it, Iterable) and children in it @@ -657,9 +659,7 @@ def __setitem__(self, key, value): return self[first_item].__setitem__(children, value) elif self._box_config["default_box"]: if children[0] == "[": - super().__setitem__( - first_item, box.BoxList(**self.__box_config(extra_namespace=first_item)) - ) + super().__setitem__(first_item, box.BoxList(**self.__box_config(extra_namespace=first_item))) else: super().__setitem__( first_item, self._box_config["box_class"](**self.__box_config(extra_namespace=first_item)) diff --git a/test/test_box.py b/test/test_box.py index a40a669..1232f3c 100644 --- a/test/test_box.py +++ b/test/test_box.py @@ -755,6 +755,7 @@ def test_get(self): assert isinstance(bx.get("a", [1, 2]), BoxList) bx_dot = Box(a=Box(b=Box(c="me!")), box_dots=True) assert bx_dot.get("a.b.c") == "me!" + assert bx_dot.get("def.not.in.the.box", 4) == 4 def test_contains(self): bx_dot = Box(a=Box(b=Box(c=Box())), box_dots=True) From adb8aa562e201260101073885db9f8c3d15533b5 Mon Sep 17 00:00:00 2001 From: Chris Griffith Date: Thu, 16 Jan 2025 12:53:28 -0600 Subject: [PATCH 2/2] version bump --- AUTHORS.rst | 2 ++ CHANGES.rst | 5 +++++ box/__init__.py | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 9072429..c713b93 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -95,3 +95,5 @@ Suggestions and bug reporting: - Коптев Роман Викторович (romikforest) - lei wang (191801737) - d00m514y3r +- Sébastien Weber (seb5g) +- Ward Loos (wrdls) diff --git a/CHANGES.rst b/CHANGES.rst index 9546d63..f74e97d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,11 @@ Changelog ========= +Version 7.3.2 +------------- + +* Fixing #288 default get value error when using box_dots (thanks to Sébastien Weber) + Version 7.3.1 ------------- diff --git a/box/__init__.py b/box/__init__.py index 5fe3311..7cd918f 100644 --- a/box/__init__.py +++ b/box/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- __author__ = "Chris Griffith" -__version__ = "7.3.1" +__version__ = "7.3.2" from box.box import Box from box.box_list import BoxList