[Python-ideas] Statement local functions and classes (aka PEP 3150 is dead, say 'Hi!' to PEP 403)

Nick Coghlan ncoghlan at gmail.com
Thu Oct 13 13:55:23 CEST 2011


On Thu, Oct 13, 2011 at 9:45 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Thu, 13 Oct 2011 09:31:35 +0200
> Georg Brandl <g.brandl at gmx.net> wrote:
>> Am 13.10.2011 07:48, schrieb Nick Coghlan:
>>
>> > Oh, I'll also note that the class variant gives you the full power of
>> > PEP 3150 without any (especially) funky new namespace semantics:
>> >
>> >     :x = property(@.get, @.set, @.delete)
>> >     class scope:
>> >         def get(self):
>> >             return __class__.attr
>> >         def set(self, val):
>> >             __class__.attr = val
>> >         def delete(self):
>> >             del __class__.attr
>>
>> Sorry, I don't think this looks like Python anymore.  Defining a class
>> just to get at a throwaway namespace?  Using "@" as an identifier?
>> Using ":" not as a suite marker?
>>
>> This doesn't have any way for a casual reader to understand what's
>> going on.
>
> Same here. This is very cryptic to me.
> (while e.g. Javascript anonymous functions are quite easy to read)

The update to the PEP that I just pushed actually drops class
statement support altogether (at least for now), but if it was still
there, the above example would instead look more like:

    postdef x = property(class.get, class.set, class.delete)
    class scope:
        def get(self):
            return __class__.attr
        def set(self, val):
            __class__.attr = val
        def delete(self):
            del __class__.attr


I think I was getting too cute and it's a bad example, though -
there's a reason I've now dropped classes from the initial scope of
the proposal (just like the original decorator PEP).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list