Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-68

PyQt4 regression: unbound signals do not provide __get__

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • P2: Important
    • 6.0
    • 1.1.0
    • PySide
    • ea89199e0ec036957dd103bb55ff480979be8622 (pyside/pyside-setup/5.15), db40e3e07 (dev), d00d4bfc6 (6.4), 08ec50ff3 (dev), 9c5b9a97e (6.4)

    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

          Activity

            People

              ctismer Christian Tismer
              blair Blair Zajac
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: