cdgriffith / Box

Python dictionaries with advanced dot notation access
https://github.com/cdgriffith/Box/wiki
MIT License
2.61k stars 106 forks source link

Allow a box to be created from None #194

Closed DaleStanbrough closed 2 years ago

DaleStanbrough commented 3 years ago

Creating a Box with a parameter of None results in an error.

BoxValueError: First argument must be mapping or iterable

The alternative is

Box(some_value or [])

which works to deliver an empty box.

The Box __init__ method could recognise this situation and create an empty Box instead.

cdgriffith commented 3 years ago

This is actually done on purpose for safety to mimic how dict operates.

>>> dict(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable