Details
Description
PyQt4 allows one to bind an unbound signal defined a QObject subclass and bind it to an instance using __get__. This is needed to write decorators that take the unbound signal because one cannot write a decorator that takes a bound signal since 'self' is not defined at decoration time.
For example, this works in PyQt4:
from PyQt4 import QtCore QtCore.Signal = QtCore.pyqtSignal QtCore.Slot = QtCore.pyqtSlot def emit_upon_success(signal): def f_(f): def f__(self): result = f(self) s = signal.__get__(self) s.emit() return result return f__ return f_ class Foo(QtCore.QObject): SIG = QtCore.Signal() @emit_upon_success(SIG) def do_something(self): pass foo = Foo() foo.do_something()
From my reading, normal python usage lets you bind any method using __get__:
class Bar(object):
def method(self):
pass
bar = Bar()
unbound_method = Bar.method
bound_method = Bar.method.__get__(bar)
So __get__ is the normal way of binding something to an instance.
Attachments
Issue Links
- resulted in
-
PYSIDE-2140 PySide2 5.15.2 introduces regression with respect to bound signal equality and identity
- Closed