Repository navigation
Conversation
KeypathDict.update() checks that keys don't contain the keypath separator, but check_keys() only inspects dicts. update([('a.b', 1)]) therefore stored the raw key 'a.b', which can't be read back afterwards (b['a.b'] raises KeyError), while update({'a.b': 1}) raises ValueError. Convert non-dict arguments to a dict before the check.
|
The bad-key check works, but could from benedict import benedict
d = benedict(keypath_separator=None)
def pairs():
yield ("a", 1)
yield ("b", d["a"] + 1)
d.update(pairs())
print(d)This prints Locally, AI-assisted investigation and review. |
With keypath_separator=None there are no keys to check, so keep passing the iterable straight to dict.update(). Converting it first broke generators that read values added earlier in the same update.
|
Thanks, you are right. Fixed in f317cc4 with the guard you suggested: the pairs are only converted to a dict when |
Describe your changes
update()only validates keys that contain the keypath separator when its argument is a dict, so a list of pairs (or any other iterable/mapping that isn't adict) skips the check:The second call stores the raw key
"a.b", which can't be read back with keypaths. The cause is thatkeypath_util.check_keys()returns early for anything that isn't a dict.KeypathDict.update()now converts a non-dict argument withdict(other)before the check, so pairs, generators and other mappings raise the sameValueErroras a dict. Dict arguments are passed through unchanged (no extra copy).Unchanged:
update()with no arguments,**kwargs,keypath_separator=None, benedict arguments (also in pointer mode), and theTypeErrorfor invalid arguments such asupdate(5).Related issue
None, found while testing
update()with different argument types.Checklist before requesting a review
New
test_update_with_pairs_with_separator_in_keysfails without the change and passes with it.tests/dicts/keypath/test_keypath_dict.pyandtests/dicts/test_benedict.pypass, except three yaml/xml tests that fail the same way without the change because I don't have those extras installed.ruff check/ruff format --checkclean.