-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
BuiltinData is Union type but fails isinstance #70
Comments
Hi @juliusfrost, You can not check what instance something that's not a PlutusData object is right now... though I will have to think about changing that to allow BuiltinData. Suggestions to fix the problem at hand:
|
I have updated the error message in bda9171 Currently it is also not allowed to introduce user-defined Union types with PlutusData and int/bytes/list/dict.
I have a bit of a philosophical issue with isinstance checks on Anything/BuiltinData, because they give the wrong impression of there actually being a type check performed, which is not what happens. from eopsin.prelude import *
@dataclass()
class A(PlutusData):
x: int
@dataclass()
class B(PlutusData):
y: int
def validator(z: BuiltinData) -> None:
if isinstance(z, A):
print("Is A with " + str(z.x))
if isinstance(z, B):
print("Is B with " + str(z.y)) If I give it
isinstance can only reasonably check the constructor id as the actual class name is not encoded in the object itself. To contrast this, the following will just not compile, resulting in a safer program from eopsin.prelude import *
@dataclass
class A(PlutusData):
x: int
@dataclass
class B(PlutusData):
y: int
def validator(z: Union[A, B]) -> None:
if isinstance(z, A):
print("Is A with " + str(z.x))
if isinstance(z, B):
print("Is B with " + str(z.y))
The current way of writing it with BuiltinData is this, which makes more clear what is actually happening from eopsin.prelude import *
@dataclass()
class A(PlutusData):
x: int
@dataclass()
class B(PlutusData):
y: int
def validator(z: BuiltinData) -> None:
z_a: A = z
print("Is A with " + str(z_a.x))
z_b: B = z
print("Is B with " + str(z_b.y)) |
Describe the bug
Anything
,PlutusData
,BuiltinData
,Redeemer
,Datum
are all equivalent topycardano.Datum
Datum = Union[PlutusData, dict, IndefiniteList, int, bytes, RawCBOR, RawPlutusData]
However, eopsin does not allow compilation with
isinstance
.To Reproduce
Use
eopsin compile
on the following script:Error message:
Expected behavior
Script compiles and above types function as Union type.
Additional context
Relevant code snippet:
https://github.com/ImperatorLang/eopsin/blob/cee2aa9bb2910732f283ff9ac69e870a94024770/eopsin/type_inference.py#L222-L262
The text was updated successfully, but these errors were encountered: