Closed inducer closed 11 months ago
Thanks for taking a look!
As a side note, while playing around with https://github.com/matthiasdiener/orderedsets , I noticed that immutables.Map
is also not deterministic, in contrast to dict
/frozendict
, e.g.:
from immutables import Map
from frozendict import frozendict
m = Map({"a": None, "b": None, "c": None})
d = {"a": None, "b": None, "c": None}
f = frozendict({"a": None, "b": None, "c": None})
print("map", list(m.keys()))
print("dict", list(d.keys()))
print("frozendict", list(f.keys()))
$ python map.py
map ['b', 'a', 'c']
dict ['a', 'b', 'c']
frozendict ['a', 'b', 'c']
$ python map.py
map ['a', 'c', 'b']
dict ['a', 'b', 'c']
frozendict ['a', 'b', 'c']
Yep, I know. And that's OK. I also discussed this with @majosm the other day. Rather than rely on insertion orders throughout, I would prefer to have code generation be deterministic by construction, e.g. by sorting during traversals. That's also the direction that this PR takes.
Best viewed commit-by-commit.
cc @majosm