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 / [EMAIL PROTECTED] / http://blog.ianbicking.org _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com