My favorite declarative-namedtuple hack is <a href="http://code.activestate.com/recipes/500261-named-tuples/#c16" target="_blank">http://code.activestate.com/recipes/500261-named-tuples/#c16</a><br><br>Devin<br><br><div class="gmail_quote">
On Sat, Aug 6, 2011 at 3:50 PM, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On 8/6/2011 2:53 AM, Eric Snow wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sat, Aug 6, 2011 at 12:37 AM, Carl Matthew Johnson<br>
<<a href="mailto:cmjohnson.mailinglist@gmail.com" target="_blank">cmjohnson.mailinglist@gmail.<u></u>com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As another example, using metaclasses you can change namedtuple's syntax from the somewhat clunky<br>
<br>
Point = namedtuple('Point', 'x y')<br>
<br>
to the more elegant but confusing since it uses "class"<br>
<br>
class Point(NamedTuple):<br>
x<br>
y<br>
</blockquote></blockquote>
<br></div>
If NamedTuple were documented as having a custom metaclass, and if this were a common idiom, that would not be too confusing as all.<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You don't even need to use __prepare__() if you make it look like this:<br>
<br>
@as_namedtuple<br>
class Point:<br>
x = ...<br>
y = ...<br>
<br>
Since Ellipsis became valid as a normal-use object this works. And<br>
that decorator is a snap to write.<br>
</blockquote>
<br></div>
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.<br><font color="#888888">
<br>
-- <br>
Terry Jan Reedy</font><div><div></div><div><br>
<br>
______________________________<u></u>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br>