-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Short description
Found a small bug in SignalProxy.__init__() that occurs when creating an instance of SignalProxy without directly handing over a slot to connect to.
The default value for the optional init parameter slot is None and so you can not create a weakref from that.
The culprit is line 38 of SignalProxy.py https://github.com/pyqtgraph/pyqtgraph/blob/develop/pyqtgraph/SignalProxy.py#L38
My proposal would be to get rid of the instance attribute self.slot entirely since you only use it for disconnection in SignalProxy.disconnect. This is not needed as you could simply call self.sigDelayed.disconnect() without any arguments.
This would be even better since it would disconnect ALL slots (even the ones "manually" connected) from sigDelayed as the user would expect from calling disconnect on any QObject (see also https://doc.qt.io/qt-5/qobject.html#disconnect).
Code to reproduce
# -*- coding: utf-8 -*-
import pyqtgraph as pg
import numpy as np
class Dummy(pg.QtCore.QObject):
sigTest = pg.QtCore.Signal()
def my_slot():
pass
if __name__ == '__main__':
app = pg.QtCore.QCoreApplication([])
dummy_obj = Dummy()
proxy = pg.SignalProxy(dummy_obj.sigTest) # raises TypeError
proxy.sigDelayed.connect(dummy_obj.my_slot)
# This would work instead:
# proxy = pg.SignalProxy(dummy_obj.sigTest, slot=dummy_obj.my_slot)Expected behavior
One should be able to create instances of SignalProxy by just passing the sender signal.
It seems like this was intended behaviour, as it should be, since it can be beneficial to create a proxy and connect the receiving slot later.
Real behavior
Traceback (most recent call last):
File ".\pg_signal_proxy_test.py", line 15, in <module>
proxy = pg.SignalProxy(dummy_obj.sigTest) # raises TypeError
File "C:\Program Files\Python37\lib\site-packages\pyqtgraph\SignalProxy.py", line 38, in __init__
self.slot = weakref.ref(slot)
TypeError: cannot create weak reference to 'NoneType' object
Tested environment(s)
- PyQtGraph version: 0.10.0.4
- Qt Python binding: PyQt5 5.9.2 Qt 5.9.3
- Python version: 3.7.7
- NumPy version: 1.18.3
- Operating system: Debian 10 (stable) & Win10 Enterprise (10.0.18363)
- Installation method: pip