Make pyqtBoundSignals from the same signal/instance be equal

Kyle Altendorf sda at fstab.net
Thu Jul 9 00:59:13 BST 2020


Phil,

What do you think of making pyqtBoundSignals that come from the same 
instance and signal compare as equal?  To be complete, this would lead 
to them also needing to hash the same.  It came up while coding:


https://github.com/altendky/qtrio/blob/master/qtrio/_core.py#L109-L125

     def is_from(self, signal: SignalInstance) -> bool:
         """Check if this emission came from `signal`.
         Args:
             signal: The signal instance to check for being the source.
         """

         # TODO: `repr()` here seems really bad.
         if qtpy.PYQT5:
             return self.signal.signal == signal.signal and 
repr(self.signal) == repr(
                 signal
             )
         elif qtpy.PYSIDE2:
             # TODO: get this to work properly.
             return bool(self.signal == signal)

         raise qtrio.QTrioException()  # pragma: no cover


For use like:


https://github.com/altendky/qtrio/blob/master/qtrio/examples/emissions.py#L110-L118

         async for emission in emissions.channel:
             if emission.is_from(window.decrement.clicked):
                 window.decrement_count()
             elif emission.is_from(window.increment.clicked):
                 window.increment_count()
             elif emission.is_from(window.widget.closed):
                 break
             else:  # pragma: no cover
                 raise qtrio.QTrioException(f"Unexpected emission: 
{emission}")


Thanks as always for your time.

Cheers,
-kyle


More information about the PyQt mailing list