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

shibturn shibturn at gmail.com
Thu Oct 13 15:18:48 CEST 2011


On 13/10/2011 8:32am, Eric Snow wrote:
> 2. namespaces
>
> I hate using a class definition as a plain namespace, but the
> following is cool (if I'm reading this right):
>
>     :some_func(@.x, @.y)
>     class _:
>         x = 4
>         y = 1
>
> and given a purer namespace (like http://code.activestate.com/recipes/577887):
>
>     :some_func(**@)
>     @as_namespace
>     class _:
>         x = 4
>         y = 1

I would rather ressurect PEP 3150 but make

   STATEMENT_OR_EXPRESSION given:
     SUITE

equivalent to something like

   def _anon():
     SUITE
     return AtObject(locals())
   @ = _anon()
   STATEMENT_OR_EXPRESSION
   del @

where AtObject is perhaps defined as

   class AtObject(object):
     def __init__(self, d):
       self.__dict__.update(d)

Then you could do

   some_func(@.x, @.y) given:
     x = 4
     y = 1

and

   x = property(@.get, @.set) given:
     def get(self):
       ...
     def set(self, value):
       ...

Wouldn't this be cleaner/simpler to implement than the old PEP 3150? 
Certainly prettier to my eyes than the new proposal -- I want my 
subordinate definitions indented.

Cheers,
sbt




More information about the Python-ideas mailing list