Quiddity initialization
Issue
Summary
I think there is some problems with Quiddity initialization within the pyquid
wrapper.
While testing the switcherio
wrapper from feat/switcher-ws, a TypeError exception: error parsing arguments
was caught at the on_quiddity_created signal callback.
received event "quiddity.create" from C0Y01qiRAAABbHC0Y01 [/]
Traceback (most recent call last):
File "/home/ubuntu/switcher/wrappers/switcherio/server.py", line 47, in on_quiddity_created
quiddities[quid_id] = sw.get_quid(quid_id)
TypeError: error parsing arguments
This is because of the introduction of the possibility to initialize pyquid.Quiddity
instances using the python class by embedding a reference to the pyquid.Switcher
instance to use for required calls to the C++ interface.
Within the C++ code base, there is the Container
concept that manages Quiddity instances. This concept should be ported to pyquid
to both fix and ease the management of quiddities.
Whenever a Quiddity instance is created, a reference to the newly created python object that wraps the C++ instance should be kept within the Switcher instance, something like a non-editable (except by a switcher method or using the Quiddity class)
sw.quiddities
attribute that returns a new list of current Quiddity objects anytime it is accessed.
This is a quite straighforward approach:
print(sw.quiddities)
>>> [ <Quiddity (1) at 0x7fb3860dc3b0>, <Quiddity (2) at 0x7fb3860dc430>]
print(sw.quiddities[0])
>>> <Quiddity (1) at 0x7fb3860dc3b0>
Right now, most common ways to initialize a Quiddity instance in pyquid
are as follows:
- Using a method from an instance of
pyquid.Switcher
quid = sw.create(type [, name])
- Using the
pyquid.Quiddity
class by embedding apyquid.Switcher
instance:
quid = Quiddity(switcher, type [, name, opts])
How to reproduce ?
- Clone the repo and checkout the
feat/switcher-ws
branch - Compile, install and link
switcher
- Run the following program using python 3.8
import pyquid
sw = pyquid.Switcher('test')
quid = sw.create('dummy', 'dummy1')
quid_1 = sw.get_quid(1)
Expected behavior
The get_quid(quid_id) should return the exact same python object that was created by the sw.create(type, name) or the Quiddity class calls.
As of now, the former is trying to wrap an id from a given quiddity within a PyCapsule and use this object as a single argument to create a Quiddity class
Whenever a Quiddity instance is created, a reference to the newly created python object that wraps the C++ instance should be kept within the Switcher instance, something like a non-editable (except by a switcher method or using the Quiddity class)
sw.quiddities
attribute that returns a new list of current Quiddity instances anytime it is accessed.
The Quiddity init method was updated by commit 8ec6fda6 to accept a switcher
instance and a type
as required arguments.
This breaks get_quid(quid_id) since the initialization function signature has changed.
What is the frequency of occurrence of this behavior ?
Anytime a call to get_quid(quid_id) is issued.