A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-September/141430.html below:

[Python-Dev] tp_finalize vs tp_del sematics

[Python-Dev] tp_finalize vs tp_del sematics [Python-Dev] tp_finalize vs tp_del sematicsValentine Sinitsyn valentine.sinitsyn at gmail.com
Thu Sep 3 09:23:48 CEST 2015
Hi Armin,

On 25.08.2015 13:00, Armin Rigo wrote:
> Hi Valentine,
>
> On 25 August 2015 at 09:56, Valentine Sinitsyn
> <valentine.sinitsyn at gmail.com> wrote:
>>> Yes, I think so.  There is a *highly obscure* corner case: __del__
>>> will still be called several times if you declare your class with
>>> "__slots__=()".
>>
>> Even on "post-PEP-0442" Python 3.4+? Could you share a link please?
>
> class X(object):
>      __slots__=()     # <= try with and without this
>      def __del__(self):
>          global revive
>          revive = self
>          print("hi")
>
> X()
> revive = None
> revive = None
> revive = None
By accident, I found a solution to this puzzle:

class X(object):
     __slots__ = ()

class Y(object):
     pass

import gc
gc.is_tracked(X())  # False
gc.is_tracked(Y())  # True

An object with _empty_ slots is naturally untracked, as it can't create 
back references.

Valentine
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4