Nick Coghlan added the comment:

Adding Guido because this appears to be due to a longstanding difference 
between the handling of tp_del and most other slots

Specifically, the reason for the odd behaviour appears to be that generator 
objects define tp_del [1] (which is what the cyclic gc *really* looks for), but 
while defining __del__ in Python will populate tp_del in the type slots, 
defining tp_del directly in a builtin or extension type doesn't create an 
exposed __del__ at the Python level (there's no wrapper function identified in 
the slot definition).

So, at the very least, the fact that builtin and extension types can define 
tp_del without creating a visible __del__ method needs to be documented as a 
CPython implementation detail.

However, I'm not sure we actually have a good *reason* for tp_del failing to 
generate __del__ automatically - it's been that way since Guido implemented it 
[2], but Guido's comment in that commit message about not needing a wrapper 
because types written in C can't define tp_del is clearly no longer accurate.

[1] http://hg.python.org/cpython/file/2.7/Objects/genobject.c#l328
[2] http://hg.python.org/cpython/annotate/71dca7c76fa2/Objects/typeobject.c#3955

----------
nosy: +gvanrossum
versions: +Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17468>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to