[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Suggestion: connect overloaded signal based on callable signature (as returned by inspect
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2016-01-24 18:33:30
Message-ID: A46CCFE3-4212-4162-99B1-8F20DE618FCD () riverbankcomputing ! com
[Download RAW message or body]
On 16 Jan 2016, at 7:07 am, Antony Lee <antony.lee@berkeley.edu> wrote:
>
> Consider the following example:
>
> from functools import wraps
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> def decorator(func):
> @wraps(func)
> def wrapper(*args, **kwargs):
> return func(*args, **kwargs)
> return wrapper
>
> class C(QComboBox):
> @decorator
> def method(self):
> print("here")
>
> app = QApplication([])
> c = C()
> c.activated.connect(c.method)
> c.activated.emit(1)
>
> This fails (also under PyQt5) with "TypeError: method() takes 1 positional argument \
> but 2 were given", i.e. the connection was made using the "activated[int]" signal \
> overload. But the actual signature of "c.method" (as taking no argument) is in \
> fact available (since Python 3.3) via "inspect.signature".
> I am thus suggesting to rely on "inspect.signature" for the overload resolution. \
> (I am aware that decorating with pyqtSlot() can also resolve the ambiguity.)
> Thoughts?
At this stage it would be a lot of effort (to parse the signature and translate it \
into an equivalent C++ version) for little benefit.
Had this been available when pyqtSlot() was invented, then it might have been worth \
it.
Phil
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic