[issue43310] Method __del__ with callable

2021-02-24 Thread Mark Dickinson
Mark Dickinson added the comment: Postscript: the "MethodType" that appears in the previous comment can be imported from the types module: "from types import MethodType". -- ___ Python tracker _

[issue43310] Method __del__ with callable

2021-02-24 Thread Mark Dickinson
Mark Dickinson added the comment: The key difference between the func_del function and the instance C() is that func_del is a (non-data) descriptor in addition to being callable, while the instance C() is not. That makes func_del usable as a method. If you define C as follows, you'll see the

[issue43310] Method __del__ with callable

2021-02-24 Thread Erik Soma
Erik Soma added the comment: You can wrap your callable in a regular function: ``` def hack_c(): c = C() def _(*args, **kwargs): return c(*args, **kwargs) return _ A.__del__ = hack_c() ``` Or (untested) make your callable an extension type with Py_TPFLAGS_METHOD_DESCRIPTOR

[issue43310] Method __del__ with callable

2021-02-23 Thread Andrey Petukhov
New submission from Andrey Petukhov : 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