[Python-Dev] Second round: arbitrary function and method attributes

Greg Stein gstein@lyra.org
Wed, 12 Apr 2000 01:09:30 -0700 (PDT)


On Tue, 11 Apr 2000, Barry A. Warsaw wrote:
> Here's the second go at adding arbitrary attribute support to function
> and method objects.  Note that this time it's illegal (TypeError) to
> set an attribute on a bound method object; getting an attribute on a
> bound method object returns the value on the underlying function
> object.  First the diffs, then the test case and test output.

In the instancemethod_setattro function, it might be nice to do the speed
optimization and test for sname[0] == 'i' before hitting the strcmp()
calls.

Oh: policy question: I would think that these attributes *should* be
available in restricted mode. They aren't "sneaky" like the builtin
attributes.

Rather than PyMapping_Get/SetItemString()... PyObject_Get/SetItem() should
be used. They apply to mappings and will be faster. Note that (internally)
the PyMapping_Get/SetItemString use the latter forms (after constructing a
string object(!)).
... whoops. I see that the function object doesn't use the ?etattro()
variants. hrm.

The stuff is looking really good!

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/