[Python-ideas] anonymous object support

Terry Reedy tjreedy at udel.edu
Sun Aug 7 22:46:19 CEST 2011


On 8/7/2011 8:26 AM, Guido van Rossum wrote:
> 2011/8/6 Carl Matthew Johnson<cmjohnson.mailinglist-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>:

>> def _namedtuple(func):
>>     return namedtuple(func.__name__, func.__code__.co_varnames)
>>
>> @_namedtuple
>> def Point(x,y):
>>     pass
>>
>> That is very clever, but it kind of illustrates my point about needing a new keyword. When you see "def" don't you naturally think, "OK, what comes out of this will be a function named Point." But what comes out of this is not a function. It's a namedtuple, which is quite different…
>
> I'm not sure I find that much of an objection. There are plenty of
> situations where decorators are used to seriously pervert the type of
> the defined name. Plus, what's a function? A class can be called as
> well. What's the difference?

Calling the decorator NamedTuple might hint that the decorated result is 
the type of function we call a class.

-- 
Terry Jan Reedy





More information about the Python-ideas mailing list