-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PlutusData parsing does not handle modern type hints #287
Comments
What error are you referring to specifically? I tried: @dataclass
class TestList(PlutusData):
a: List[bytes]
vals = [b'hello', b'world']
TestList(a=vals) and @dataclass
class TestList(PlutusData):
a: list[bytes]
vals = [b'hello', b'world']
TestList(a=vals) Both examples above worked without errors. |
Oops, like I had a mistake in my code blurb. I'm still getting an error though. This is what I have: from dataclasses import dataclass
from pycardano import PlutusData
@dataclass
class Test(PlutusData):
a: list[bytes]
Test(a=[b"hello", b"world"]) This is the error I get: Traceback (most recent call last):
File "/config/workspace/test.py", line 10, in <module>
Test(a=[b"hello", b"world"])
File "<string>", line 4, in __init__
File "/config/workspace/.venv/lib/python3.10/site-packages/pycardano/plutus.py", line 533, in __post_init__
if inspect.isclass(f.type) and not issubclass(f.type, valid_types):
File "/config/.pyenv/versions/3.10.13/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class More details about my environment: pycardano==0.10.0
Python==3.10.13 Swapping out |
Ah I see, this only worked in python |
Excellent question. I kind of like having the convenience of using |
From a user's perspective, I guess you are right that we should natively support |
Hm...that is interesting. I did not realize that. I always wondered why there was an IndefiniteList, but that makes perfect sense. By definition, all Python |
Actually, I think the more appropriate mapping of a DefiniteList is probably a |
We should probably test if definite list works in Plutus before supporting it. I like the idea of introducing |
Describe the bug
PlutusData
classes honor old type hints (e.g.List[bytes]
) by usingissubclass
.Modern type hints (e.g.
list[bytes]
) fail becauselist
is not a class.This is the guilty line of code:
pycardano/pycardano/plutus.py
Line 533 in fdff5f2
To Reproduce
Create a
PlutusData
class with modern type hints and try to instantiate.Environment and software version (please complete the following information):
The text was updated successfully, but these errors were encountered: