[PyQt] Unable to weakreference pyqtBoundSignal
Kyle Altendorf
sda at fstab.net
Fri Sep 29 13:57:19 BST 2017
On 2017-09-29 04:58, Phil Thompson wrote:
> On 29 Sep 2017, at 4:22 am, Kyle Altendorf <sda at fstab.net> wrote:
>>
>> TypeError: cannot create weak reference to
>> 'PyQt5.QtCore.pyqtBoundSignal' object
>>
>> Are pyqtBoundSignals intentionally not weak referenceable? If not,
>> could it be?
>>
>> Example and output:
>> https://gist.github.com/altendky/9f942709dfc2f33019723ffff43260b1
>>
>> Since I already had it open:
>> https://docs.python.org/3/extending/newtypes.html#weakref-support
>
> They aren't because I don't really see the point. Bound signals only
> exist during the period of an emit(), connect() or disconnect().
> Having said that, bound methods are weak referenceable.
My use case was that I am creating functions dynamically to connect as
slots and
wanted hold the signal/slot pairs in a WeakKeyDictionary I could later
use to
disconnect them. Instead I just apply the same logic to get the same
signals
again to disconnect. Using the slot as a weak key just seemed a bit
more direct.
But perhaps I am misunderstanding something. You say the the bound
signal only
exists _during_ an emit/connect/disconnect? I'm not sure what's going
on there.
I explored a little but didn't find anything enlightening. The id() of
the signal
is the same when accessed repeatedly and
inspect.is{data,method,member}descriptor()
all return False in my checks.
https://gist.github.com/altendky/7096674b424af3ed8d80e47a41af3169
If you have time to explain a little I would be interested to learn.
> I'll add it to the TODO list - but not high priority.
Thanks for the consideration, since I already 'worked around it' the low
priority
isn't an issue for me and perhaps an explanation would show an error in
my
desires anyways.
Cheers,
-kyle
More information about the PyQt
mailing list