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 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)