Bug or wart? You make the call.
tjreedy at udel.edu
Fri Mar 7 21:09:07 CET 2003
"Inyeol Lee" <inyeol.lee at siimage.com> wrote in message
news:mailman.1047060434.6886.python-list at python.org...
> On Thu, Mar 06, 2003 at 12:14:44AM -0500, Terry Reedy wrote:
> > Try Spam.__dict__['eggs'] without assignment, as you did with
> > 'Spam.eggs' above and see what type of object you are assigning
> > This should answer your question.
> I'm a little bit confused. It seems that we cannot add arbitrary
> attributes to class methods, but can add them to functions. Is it
> correct? Is there any specific reason for this difference?
Did you try the experiment? The point is that a 'method' is just a
wrapper for a function. You can add attributes to a function object
regardless of whether it is wrapped or not -- the function does not
know or care either way. You cannot, apparently, add attributes to
the method wrapper, whether of the unbound or bound types. There was
a reason for adding attributes to functions. Certain people has
certain specific uses for such and made the request that the
capability be added. No one has done the same for method objects,
and, given the cost of doing so, and the ease of putting the
attributes on the wrapped function, I do not expect to see such a
Terry J. Reedy
More information about the Python-list