New submission from Andrey Petukhov <andribas...@gmail.com>:

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

if so, how to get self variable?

class A(object):
    """A."""


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


def func_del(*args, **kwargs):
    """Method."""
    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 <rep...@bugs.python.org>
<https://bugs.python.org/issue43310>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to