[Python-ideas] anonymous object support
Devin Jeanpierre
jeanpierreda at gmail.com
Sun Aug 7 00:53:21 CEST 2011
My favorite declarative-namedtuple hack is
http://code.activestate.com/recipes/500261-named-tuples/#c16
Devin
On Sat, Aug 6, 2011 at 3:50 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 8/6/2011 2:53 AM, Eric Snow wrote:
>
>> On Sat, Aug 6, 2011 at 12:37 AM, Carl Matthew Johnson
>> <cmjohnson.mailinglist at gmail.**com <cmjohnson.mailinglist at gmail.com>>
>> wrote:
>>
>>> As another example, using metaclasses you can change namedtuple's syntax
>>> from the somewhat clunky
>>>
>>> Point = namedtuple('Point', 'x y')
>>>
>>> to the more elegant but confusing since it uses "class"
>>>
>>> class Point(NamedTuple):
>>> x
>>> y
>>>
>>
> If NamedTuple were documented as having a custom metaclass, and if this
> were a common idiom, that would not be too confusing as all.
>
>
> You don't even need to use __prepare__() if you make it look like this:
>>
>> @as_namedtuple
>> class Point:
>> x = ...
>> y = ...
>>
>> Since Ellipsis became valid as a normal-use object this works. And
>> that decorator is a snap to write.
>>
>
> This looks ok to me too. New keywords and syntax should be *very* rare and
> reserved for things that cannot be done so easily with what we have now.
>
> --
> Terry Jan Reedy
>
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110806/e01b2733/attachment.html>
More information about the Python-ideas
mailing list