[Python-Dev] Re: tp_clear return value
Guido van Rossum
guido@python.org
Wed, 09 Apr 2003 15:52:03 -0400
> On Wed, Apr 09, 2003 at 03:33:47PM -0400, Jeremy Hylton wrote:
> > Why does tp_clear have a return value? All the code I've seen returns
> > 0, but the only place that clear is called doesn't inspect its return
> > value.
[In response, Neil admitted]
> I guess I would have to say overdesign. I was thinking that tp_clear
> and tp_traverse could somehow be used by things other than the GC. In
> retrospect that doesn't seem likely or even possible. The GC has pretty
> specific requirements.
>
> In retrospect, I think both tp_traverse and tp_clear should have
> returned "void". That would have made implementing those methods
> easier. Testing for errors in tp_traverse methods is silly since
> nothing returns an error, and, even if it did, the GC couldn't handle
> it.
>
> :-(
>
> How do we sort this out? I suppose one step would be to document that
> the return values of tp_traverse and tp_clear are ignored. If we agree
> on that, I volunteer to go through the code and remove the useless tests
> for errors in the tp_traverse methods.
That's a good first step. Unfortunately changing the declaration to
void will break 3rd party extensions so that will be too painful.
--Guido van Rossum (home page: http://www.python.org/~guido/)