Skip to content

Fixing default_box_attr with a non-empty list returning an empty BoxList - #372

Open
imsurya26 wants to merge 1 commit into
cdgriffith:masterfrom
imsurya26:fix/default-box-attr-list
Open

imsurya26 wants to merge 1 commit into
cdgriffith:masterfrom
imsurya26:fix/default-box-attr-list

Conversation

@imsurya26

Copy link
Copy Markdown

When default_box_attr is a non-empty list, missing keys return an empty BoxList instead of a copy of that list:

>>> Box(default_box=True, default_box_attr=[1, {"a": 2}]).missing
BoxList([])

A dict default keeps its items (default_box_attr={"x": 1} gives {'x': 1}), and lists did too before 4.1.0 (#132), when they still went through the .copy() branch.

In Box.__get_default the list branch built box.BoxList(**config) without the default value. It now passes the list items, so each lookup gets its own BoxList (nested dicts are boxed with the same config, and changing it does not touch the default or later lookups). default_box_attr=list still gives an empty BoxList.

Added test_list_default_keeps_its_items next to the existing default_box_attr=[] test; it fails without the change. test/test_box.py, test/test_box_defaults.py and test/test_box_list.py pass apart from the test_toon_* tests, which fail the same way on master here because toon_format is not installed. Updated CHANGES.rst and AUTHORS.rst.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant