Order not preserved for config set via set()
Build: 1.1.0
For each iteration through .keys(), I set() values. They get reversed at the end. set() doesn't look like preserving order, or it reverses it.
config.yaml:
items:
foo1: bar1
foo2: bar2
foo3: bar3
code:
config = confuse.Configuration('MyGreatApp')
config.set_file("config.yaml")
config.set_file("config2.yaml") # Doesn't override items
for item in config['items'].keys():
pprint(config['items'].keys()) #A
config['items'].set(config['items'].as_str_seq())
pprint(config['items'].keys()) #B, consistent with A
Output: A: ['foo1', 'foo2', 'foo3'] B: ['foo1', 'foo2', 'foo3'] A: ['foo2', 'foo1', 'foo3'] B: ['foo2', 'foo1', 'foo3'] A: ['foo3', 'foo2', 'foo1'] B: ['foo3', 'foo2', 'foo1']
Workaround: Initial iteration through items are made reversed(). It doesn't feel safe or reliable. It only works because I override every value.
config = confuse.Configuration('MyGreatApp')
config.set_file("config.yaml")
config.set_file("config2.yaml") # Doesn't override items
for item in reversed(config['items'].keys()):
pprint(config['items'].keys()) #A
config['items'].set(config['items'].as_str_seq())
Output: A: ['foo3', 'foo2', 'foo1'] A: ['foo2', 'foo3', 'foo1'] A: ['foo1', 'foo2', 'foo3']
Hi! I'm confused by a few things in your example… first:
config.set_file("config.yaml")
config.set_file("config2.yaml") # Doesn't override items
Is this attempting to take the values from config2.yaml and "overlay" them on top of the values from config1.yaml? Is that not working, and that's why you resorted to the iteration strategy? If so, let's focus on fixing that instead of the for/set thing. Can you give more details about what you're trying to do—for example, what's in those files, and what you want to have happen?
Then, this:
config['items'].set(config['items'].as_str_seq())
What is the idea here? config['items'] is neither a string nor a sequence—so what's the intent behind using as_str_seq()?