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

PyQt4 regression: unbound signals do not provide __get__

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 1.1.0, dev
    • Fix Version/s: dev
    • Component/s: PySide
    • Labels:
    • Commits:
      ea89199e0ec036957dd103bb55ff480979be8622 (pyside/pyside-setup/5.15)

      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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            blair Blair Zajac
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes