[Python-3000] The 'make' statement PEP (was Re: Did I miss anything?)

Ian Bicking ianb at colorstudy.com
Tue Apr 11 17:52:16 CEST 2006


Nick Coghlan wrote:
> Steven Bethard wrote:
> 
>>This is potentially a Python 2.6 PEP, but it has some optional
>>extensions for Python 3000 and may be relevant to the
>>adaptation/overloading/interfaces discussion.  It proposes a make
>>statement such that:
>>    make <callable> <name> <tuple>:
>>        <block>
>>would be translated into the assignment:
>>    <name> = <callable>("<name>", <tuple>, <namespace>)
>>much in the same way that the class statement works.  I've posted it
>>to comp.lang.python and had generally positive feedback.  I've
>>submitted it for a PEP number, but I haven't heard back yet:
>>
>>http://ucsu.colorado.edu/~bethard/py/pep_make_statement.txt
>>http://ucsu.colorado.edu/~bethard/py/pep_make_statement.html
> 
> 
> Pretty nice, but I think it would be even better if instead of focusing on the
> rare use case of a callable that needs to know the name it is being bound to,
> we looked at the more general idea of "use a trailing suite to define the
> keyword arguments to a function".

I don't think an object wanting to know its name is a particularly rare 
use case.  Functions know their name, and classes know their name. 
Certainly the ElementTree-building example is better in Steven's version.

When building descriptors, they often need to know their name -- if, for 
instance, the descriptor represents any state, that state needs to be 
attached to the object, and attaching the state to a fixed location 
means that the descriptor can only be used once on that class.  Or you 
choose an arbitrary (and probably unstable) name, and make the object 
unpickleable.  property() manages to avoid this by not actually storing 
anything and just being a rather simple container for user-provided 
functions; but other more interesting descriptors can't do that.

I think this syntax has particular potential for descriptors, a 
currently underused feature in Python.  Certainly the decorator pattern 
saw a strong upsurge after the decorator syntax was introduced, so 
syntax can have a substantial impact.


-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the Python-3000 mailing list