Re:A practical usage of ChainMap in Python
by joshuamorton on Monday September 24, 2018 @01:33PM
(#18059601)
That design would have made ordered dict incompatible with dict (an ordered dict couldn't be constructed with an ordered key, same for an unordered dict), and at the time, keyword args were unordered, so an ordered dict had to be constructed with an iterable of tuples instead of key value pairs.
Re:A practical usage of ChainMap in Python
by dfee on Tuesday September 25, 2018 @03:01PM
(#18069377)
I disagree. There’s a strange precedent for builtins overloading like ‘type’. The same could be done for ‘dict’. Do you want me to share a satisficing call signature?
Re:A practical usage of ChainMap in Python
by joshuamorton on Tuesday September 25, 2018 @06:00PM
(#18070887)
Type doesn't take in kwargs?
But yes, I'm interested in the call signature you propose such that it's possible to tell whether
dict(ordered=True)
Means `OrderedDict([])` or `{'ordered': True}`.
However, it appears that the “locals, globals, builtins” lookup was the design constraint this was intended for, and the core of Python seems to prefer new classes over compact functionality. For example look at OrderedDict not just being an “ordered=“ keyword only parameter (ordered) on dict.