[New-bugs-announce] [issue43310] Method __del__ with callable

Andrey Petukhov report at bugs.python.org
Wed Feb 24 01:44:13 EST 2021

New submission from Andrey Petukhov <andribas404 at gmail.com>:

Is it possible to use callable to replace __del__ method of class?

if so, how to get self variable?

class A(object):

class C(object):
    def __call__(self, *args, **kwargs):
        print("call", args, kwargs)

def func_del(*args, **kwargs):
    print("func", args, kwargs)

def del_function():
    Test del.

    ('func', (<__main__.A object at 0x7f8ae5a82750>,), {})
    ('call', (), {})
    c = C()
    A.__del__ = func_del
    a = A()
    del a
    A.__del__ = c
    a = A()
    del a

components: Interpreter Core
messages: 387609
nosy: andribas404
priority: normal
severity: normal
status: open
title: Method __del__ with callable
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list