rocklabs-io / ic-py

Python Agent Library for the DFINITY Internet Computer
MIT License
127 stars 26 forks source link

variant enum #48

Closed Astrapolis-peasant closed 2 years ago

Astrapolis-peasant commented 2 years ago

for variant type like

 variant {
   a;
   b;
 };

use canister.xxx({"a": None}) returns AttributeError: 'NoneType' object has no attribute 'buildTypeTable'

Myse1f commented 2 years ago

Currently, variant is represented by:

None: [] (Empty list),
Some: [xxx] (list with one item)

Thus you need to use canister.xxx({"a": []})

Astrapolis-peasant commented 2 years ago

Hi, I tried canister.xxx({"a": []}). It gives the same error. I checked the source code. Enum variant is parsed as {'a': None, 'b': None}. So when

    def _buildTypeTableImpl(self, typeTable: TypeTable):
        for _, v in self._fields.items():
            v.buildTypeTable(typeTable)

This error triggers

Myse1f commented 2 years ago

Can you provide ur code to produce this error. By the way, what's the version of ic-py you used.

Astrapolis-peasant commented 2 years ago

I cloned the main repository and install it locally. To reproduce, Having a candid type like

type Side = 
 variant {
   buy;
   sell;
 };

order: (Side, nat, nat, text) -> (opt Order);

Then pass it in with canister canister = Canister(agent=agent, canister_id="rrkah-fqaaa-aaaaa-aaaaq-cai", candid=testdid)

Myse1f commented 2 years ago

Currently, variant is represented by:

None: [] (Empty list),
Some: [xxx] (list with one item)

Thus you need to use canister.xxx({"a": []})

Sry, I got it wrong. Option is used in this way.

I will look into this issue.

Myse1f commented 2 years ago

Thanks for the report. Try to fix it in #49.

You can switch to that branch and use canister.xxx({"a": None}) to test whether the result is correct.