Even if the only ordering change that was made was to magically give OrderedDict.__init__ its **kwargs in order, it would clean up these instances, which I initially referred to as literals.
foo = OrderedDict(
b=1,
a=2 )
Since PEP3115, classes can __prepare__ a custom dict:
from collections import OrderedDict
class OrderedDictBuilder(type):
@classmethod
def __prepare__(metacls, name, bases):
return OrderedDict()
def __new__(cls, name, bases, classdict):
del classdict['__module__'] # ugh
return classdict
Then we can (ab)use the Class syntax to preserve the order!