From: Steven D'Aprano email@example.com
Sent: Wednesday, May 15, 2013 8:16 PM
On 16/05/13 07:27, Andrew Barnert wrote:
The first thing you think of is, "Oh, I just need to use an
OrderedDict.". Well, technically yes, except there's no convenient way to instantiate an OrderedDict with more than one element at a time.
There's not *that* much difference between writing:
You're quoting me quoting someone else (Don Spaulding) here. The problem may be that I'm using the horrible Yahoo webmail client, which is especially bad at indenting replies to rich-text emails, and therefore it's hard for you to tell what's going on? But I think this led to some confusion farther down.
Or consider this small change to the rules for passing **kwargs. Currently,
Python guarantees to build a new dict-like object out of anything you pass, then update it. What if Python instead guaranteed to build a new mapping of the same type (e.g., via copy.copy), then update it in order? Then you could just do this:
create_element('img', alt="Some cool stuff.",
I can't help but feel that if order of keyword arguments is important, you should take an ordered dict as an explicit argument rather than accept keyword arguments.
I tossed out as wide a variety of solutions as I could come up with, to show that almost anything you come up with is either only works if it doesn't have to work for OrderedDict.__init__, or at least gets a lot easier if it doesn't have to work for OrderedDict.__init__. The one you're replying to is the last, and probably worst, of those spitballed ideas. I certainly wasn't proposing that we actually do it.
Anyway, my point is this: If the goal is to solve ordered kwargs, don't try to make that solution work for OrderedDict.__init__ (so we can use OrderedDict as part of the solution). Alternatively, if the goal is to improve OrderedDict construction, don't try to do so by solving ordered kwargs.
To be clear, going over my spitballed ideas and those earlier in the thread: I'm -0 on having a map constructor attribute/slot for functions, -0.5 on a PyPy-style argument factory attribute/slot, -0 on adding odict literals with some new syntax, -1 on adding odict literals if they look like Python 3.3 OrderedDict constructor calls, -1 on requiring kwargs to preserve the type it's handed, -1 on allowing default values for *args and **kwargs, -1 on making OrderedDict the default dictionary type, -1 on making it the type for kwargs, -0.5 on specifying that dicts must keep creation order unless items are deleted, -1 for making that change in CPython without specifying it as part of the language.