[Python-Dev] PEP 266: Catching code that is not safe for tracking

Guido van Rossum guido@python.org
Thu, 16 Aug 2001 02:46:58 -0400


> While I was out for my semi-occasion-once-every-other-wednesday run this
> afternoon, I thought about the problem of identifying objects that are not
> safe for the tracking proposal in PEP 266.  My worry is that an extension
> module that works in Python 2.2 will break in subtle ways in Python 2.3 if
> my tracking idea is enabled, because the module's code is not doing anything
> to notify the rest of the world when an attribute binding changes.
> 
> I came up with the following possible solution.  Add a new slot to type
> objects that the object's author must explicitly set to Py_TRACKING_SAFE
> (1?).  It would default to Py_TRACKING_UNSAFE (0?).  This value could be
> checked by _PyObject_TrackName and a warning raised if a program tries to
> track an unsafe object.
> 
> Would that work?

I have yet to find the time to read PEP 266, but I expect so -- this
is how I solve many such concerns in 2.2 already (e.g. an extension
type is only subclassable if it has the Py_TPFLAGS_BASETYPE flag,
which is not included in Py_TPFLAGS_DEFAULT).

--Guido van Rossum (home page: http://www.python.org/~guido/)