|
Thanks for the illustrative example Raiden! My changes only removed make_historic() for direct assignments to historic (aka "prvalues"), not to variable assignments. This somewhat reduces the risk of dictionaries being modified. Separately, I think the Python reference semantics may not be clear to everyone, especially if innerdict gets reassigned from primitives to/from dict, which could happen for fields like logcomponentverbosity. Since most primitives are not passed by reference, we can encourage users to treat dictionaries as immutable types where possible.
|
|
Just as a note, I'd originally avoided implicitly converting stored dicts to HistoryDict because it can lead to unintuitive behavior with python reference semantics. For example:
outerdict = make_historic({})
|
innerdict = {"foo": "bar"}
|
outerdict["inner"] = make_historic(innerdict)
|
|
innerdict["foo2"] = "bar2"
|
outerdict["inner"]["foo"] # returns "bar"
|
outerdict["inner"]["foo2"] # keyerror, would've worked if these were all normal dicts
|
In the above example, having the make_historic external to the dict forces users to recognize that they're distinct references; having it internal to the set method could've been confusing.
|