Open wimglenn opened 1 year ago
Nested containers remain an ConfigNode
instances after mutation, reproducer:
>>> cfg = Config({"a": {"k1": [], "k2": {}}})
>>> cfg.a = dict(sorted(cfg.a.items(), reverse=True))
>>> cfg.data
{'a': {'k2': configurator.node.ConfigNode({}), 'k1': configurator.node.ConfigNode([])}}
Yeah, I feel like this is a tough one. Like we talked about: configurator
should arguably strip off the ConfigNode
wrapper at assignment time, but there will likely be cases where this doesn't work (assigning a dict mapping to ConfigNodes, etc).
I feel like the answer might want to be "you should be using the mapping/merging APIs" but want to leave this open for the next time I have a proper chance to play with this project...
I noticed that
Config.__eq__
isn't implemented so we just getobject.__eq__
comparison (identity based)Would it be possible to get a content-based equality comparison? In the simple example above we could just use
c1.data == c2.data
, but my real use-case has a nested configuration so comparing data attributes doesn't work either: the nested values are instances ofConfigNode
, which also has identity-based comparison.My use-case is in testing comparisons, where we want to assert some configs from multiple sources have been parsed and layered the way we expected, without having to recursively extract all the content from the
Config
instance. i.e., just compare with an "expected"Config
orConfigNode
instance directly.