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
For Gerrit Dashboard: PYSIDE-68 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
314265,5 | signal: perform a cleanup before fixing __get__ | 5.15 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
314351,10 | signal: Supply the missing __get__ method | 5.15 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
354381,3 | Update blacklist.txt for errors in debug mode | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
354834,2 | Update blacklist.txt for errors in debug mode | 6.1 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
456357,7 | signals: Introduce Weak Reference to protect lost SignalInstance | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
457731,16 | signal: Finally clean up all leaks after complete understanding | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
457976,2 | signals: Introduce Weak Reference to protect lost SignalInstance | 6.4 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
461637,2 | signal: Finally clean up all leaks after complete understanding | 6.4 | pyside/pyside-setup | Status: MERGED | +2 | 0 |