[Python-Dev] PyObject_SetAttr - is it the only way types should set attributes?

Skip Montanaro skip@pobox.com (Skip Montanaro)
Wed, 15 Aug 2001 12:02:00 -0500


    SM> In thinking about the implementation of TRACK_GLOBAL some more, I'm
    SM> trying to figure out where object updating is going to take place.
    SM> Is PyObject_GenericSetAttr the only way C-based objects should set
    SM> attributes?

    Jeremy> C code can manipulate __dict__, too, right?  It's a pretty
    Jeremy> common idiom to get a module dictionary and use
    Jeremy> PyDict_SetItem().

Yeah, I believe so.  In theory, I think any code that could modify what
LOAD_GLOBAL or LOAD_ATTR instructions might return would have to be changed
to signal an update.

    Jeremy> I'm also curious about the new type-class unification stuff.  Is
    Jeremy> it possible to modify a C object via something like a C struct
    Jeremy> and have that change be visible as a modified attrbute at the
    Jeremy> Python level?

If a C extension defines a function that changes an exposed attribute I
suspect it would have to be changed.  I'll try and make this notification as
easy as possible for the programmer (a single function call), but it would
definitely require extension writers to be pretty careful in updating to a
version of Python that contains this functionality.  In the stuff I've seen
so far this seems to be the most difficult problem to resolve.

Skip