[Python-ideas] Anonymous namedtuples
Eric Snow
ericsnowcurrently at gmail.com
Wed Apr 20 12:00:46 EDT 2016
On Tue, Apr 19, 2016 at 4:06 AM, Chris Angelico <rosuav at gmail.com> wrote:
> There have been proposals to have kwargs retain some order (either by
> having it actually be an OrderedDict, or by changing the native dict
> type to retain order under fairly restricted circumstances). With
> that, you could craft the factory function easily.
>
> It may be worth dusting off one of those proposals and seeing if it
> can move forward.
FYI, PEP 468: "Preserving the order of **kwargs in a function." [1]
The PEP exists for exactly the sort of use case being discussed here.
In my case it was an alternate enum proposal I was making back when
enums were under discussion. Regardless, I'd still like to see the
PEP land. It's just a matter of finding time. I'll see if I can get
some consensus leading up to and at PyCon next month.
The actual implementation for PEP 468 is almost trivial. Now that we
have a C-implementation of OrderedDict, it's mostly just a matter of
addressing performance concerns [2], particularly those expressed by
Guido, or falling back to one of the alternatives discussed in the
PEP.
Note that a related concept is represented with my work to make the
class definition namespace ordered by default. [3] It would allow
class decorators to have access to the order in which the class's
attributes were defined.
-eric
[1] https://www.python.org/dev/peps/pep-0468/
[2] https://www.python.org/dev/peps/pep-0468/#performance
[3] http://bugs.python.org/issue24254
More information about the Python-ideas
mailing list