Erik Soma <[email protected]> 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.
Or instead of monkey-patching __del__ make __del__ call it:
```
class A:
my_del = lambda *args, **kwargs: None
def __del__(self):
self.my_del(self)
A.my_del = C()
```
This doesn't just apply to __del__, other dunders exhibit this behavior as
well. It is unintuitive, but I'm pretty sure it's not a bug.
----------
nosy: +esoma
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43310>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com