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
4 changes: 2 additions & 2 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ def get(self, key, default=NO_DEFAULT):
else:
return None
if isinstance(default, dict) and not isinstance(default, Box):
return Box(default)
return self._box_config["box_class"](default, **self.__box_config(extra_namespace=key))
if isinstance(default, list) and not isinstance(default, box.BoxList):
return box.BoxList(default)
return box.BoxList(default, **self.__box_config(extra_namespace=key))
return default
return self[key]

Expand Down
16 changes: 16 additions & 0 deletions test/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,22 @@ def test_get(self):
assert bx_dot.get("a.b.c") == "me!"
assert bx_dot.get("def.not.in.the.box", 4) == 4

def test_get_default_keeps_box_config(self):
bx = Box(box_dots=True, default_box=True, camel_killer_box=True)
default = bx.get("missing", {"a": {"b": 1}, "CamelCase": 2})
assert default["a.b"] == 1
assert default.camel_case == 2
assert isinstance(default.not_there, Box)
listed = bx.get("missing", [{"a": {"b": 1}}])
assert isinstance(listed, BoxList)
assert listed["[0].a.b"] == 1

class MyBox(Box):
pass

assert type(MyBox().get("missing", {"a": 1})) is MyBox
assert "missing" not in bx

def test_contains(self):
bx_dot = Box(a=Box(b=Box(c=Box())), box_dots=True)
assert "a.b.c" in bx_dot
Expand Down