[Python-ideas] Ordered storage of keyword arguments

M.-A. Lemburg mal at egenix.com
Fri Oct 29 11:15:42 CEST 2010

Antoine Pitrou wrote:
> On Fri, 29 Oct 2010 10:30:26 +0200
> "M.-A. Lemburg" <mal at egenix.com> wrote:
>> Greg Ewing wrote:
>>> M.-A. Lemburg wrote:
>>>> Python has always tried
>>>> to make the most common use case simple, so asking programmers to
>>>> use a meta-class to be able to access the order of definitions
>>>> in a class definition isn't exactly what the normal Python
>>>> programmer would expect.
>>> But needing to know the order of definitions in a class
>>> is a very uncommon thing to want to do in the first
>>> place.
>> I've already pointed to a couple of existing use cases where the
>> authors had to play all sorts of tricks to access the order of
>> such definitions.
>> Since Python programs are executed sequentially (within the resp.
>> scope) in the order given in the source file, it is quite natural
>> to expect this order to be accessible somehow.
>> If it were easier to access this order, a lot of the extra magic
>> needed to map fixed order records to Python classes could go
>> away.
> Interestingly, this order is already accessible on the code object used
> to build the class namespace:
>>>> def f():
> ...   class C:
> ...     x = 5
> ...     def y(): pass
> ...     z = 6
> ... 
>>>> code = f.__code__.co_consts[1]
>>>> code.co_names
> ('__name__', '__module__', 'x', 'y', 'z')

Interesting indeed and I kind of expected that order to be
available somewhere via the compiler.

Can this be generalized to arbitrary classes ?

Would other Python implementations be able to provide the
same information ?

If so, we could add this order as .__deforder__ tuple to class

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Oct 29 2010)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-ideas mailing list