Skip to content

Commit

Permalink
Version 6.0.1 (#219)
Browse files Browse the repository at this point in the history
* Fixing #218 Box dots would not raise KeyError on bad key (thanks to Cliff Wells)
* Fixing #217 wording in readme overview needed updated (thanks to Julie Jones)
  • Loading branch information
cdgriffith authored Mar 16, 2022
1 parent 985df83 commit b1a0fc9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

Version 6.0.1
-------------

* Fixing #218 Box dots would not raise KeyError on bad key (thanks to Cliff Wells)
* Fixing #217 wording in readme overview needed updated (thanks to Julie Jones)

Version 6.0.0
-------------

Expand Down
16 changes: 9 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ If you have any issues please open a github issue with the error you are experie
Overview
========

`Box` is designed to be an easy drop in transparently replacements for
dictionaries, thanks to Python's
duck typing capabilities, which adds dot notation access. Any sub
dictionaries or ones set after initiation will be automatically converted to
a `Box` object. You can always run `.to_dict()` on it to return the object
and all sub objects back into a regular dictionary.
`Box` is designed to be a near transparent drop in replacements for
dictionaries that add dot notation access and other powerful feature.

There are a lot of `types of boxes <https://github.com/cdgriffith/Box/wiki/Types-of-Boxes>`_
to customize it for your needs, as well as handy `converters <https://github.com/cdgriffith/Box/wiki/Converters>`_!

Keep in mind any sub dictionaries or ones set after initiation will be automatically converted to
a `Box` object, and lists will be converted to `BoxList`, all other objects stay intact.

Check out the `Quick Start <https://github.com/cdgriffith/Box/wiki/Quick-Start>`_ for more in depth details.

Expand All @@ -116,7 +118,7 @@ sure everything stored in the dict can be accessed as an attribute or key value.
small_box = Box({'data': 2, 'count': 5})
small_box.data == small_box['data'] == getattr(small_box, 'data')
All dicts (and lists) added to a `Box` will be converted on lookup to a `Box` (or `BoxList`),
All dicts (and lists) added to a `Box` will be converted on insertion to a `Box` (or `BoxList`),
allowing for recursive dot notation access.

`Box` also includes helper functions to transform it back into a `dict`,
Expand Down
2 changes: 1 addition & 1 deletion box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

__author__ = "Chris Griffith"
__version__ = "6.0.0"
__version__ = "6.0.1"

from box.box import Box
from box.box_list import BoxList
Expand Down
8 changes: 6 additions & 2 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Box(dict):
:param default_box_attr: Specify the default replacement.
WARNING: If this is not the default 'Box', it will not be recursive
:param default_box_none_transform: When using default_box, treat keys with none values as absent. True by default
:param default_box_create_on_get: On lookup of a key that doesn't exist, create it if missing
:param frozen_box: After creation, the box cannot be modified
:param camel_killer_box: Convert CamelCase to snake_case
:param conversion_box: Check for near matching keys as attributes
Expand Down Expand Up @@ -510,7 +511,7 @@ def __getitem__(self, item, _ignore_default=False):
except BoxError:
if self._box_config["default_box"] and not _ignore_default:
return self.__get_default(item)
raise
raise BoxKeyError(str(item)) from _exception_cause(err)
if first_item in self.keys():
if hasattr(self[first_item], "__getitem__"):
return self[first_item][children]
Expand Down Expand Up @@ -589,7 +590,10 @@ def __delitem__(self, key):
and isinstance(key, str)
and ("." in key or "[" in key)
):
first_item, children = _parse_box_dots(self, key)
try:
first_item, children = _parse_box_dots(self, key)
except BoxError:
raise BoxKeyError(str(key)) from None
if hasattr(self[first_item], "__delitem__"):
return self[first_item].__delitem__(children)
if key not in self.keys() and self._box_config["camel_killer_box"]:
Expand Down
10 changes: 10 additions & 0 deletions test/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,16 @@ def test_dots(self):

_parse_box_dots({}, "-")

with pytest.raises(KeyError):
b["a.b"]
with pytest.raises(BoxKeyError):
b["a.b"]

with pytest.raises(KeyError):
del b["a.b"]
with pytest.raises(BoxKeyError):
del b["a.b"]

def test_unicode(self):
bx = Box()
bx["\U0001f631"] = 4
Expand Down

0 comments on commit b1a0fc9

Please sign in to comment.