-
Notifications
You must be signed in to change notification settings - Fork 86
fix: Pass enum values directly to TokenCreateTransaction protobuf to fix type conflict #732
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
base: main
Are you sure you want to change the base?
Conversation
…fix type conflict Signed-off-by: Pranay <[email protected]>
exploreriii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this again, you are passing the same enum literal [0,1] which means the error is not resolved - to see that, please install Pylance reading pylance.md
| initialSupply=self._token_params.initial_supply, | ||
| tokenType=token_type_value, | ||
| supplyType=supply_type_value, | ||
| tokenType=self._token_params.token_type.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In lines 490 to 494 you see we have a function that attempts to resolve
token_type_value to be like the proto --
see:
token_type_value = (
self._token_params.token_type.value
if isinstance(self._token_params.token_type, TokenType)
else int(self._token_params.token_type or 0)
)
so when you suggest
tokenType=self_token_params.token_type.value
Its doing very similar thing
Current type error:
Argument of type "int" cannot be assigned to parameter "tokenType" of type "TokenType | str | None" in function "init"
Type "int" is not assignable to type "TokenType | str | None"
"int" is not assignable to "TokenType"
"int" is not assignable to "str"
"int" is not assignable to "None"
The reason this errors is because either the type checker is not able to pick up on the correct type in the proto, or the underlying protobuf expects tokenType: TokenType | str | None
Currently, it thinks we are passing ints, even if you delete the int normalisation (lines 490 to 494, and just provide your idea, it will still conflict as it would be type Literal[0,1]
SOLUTION
the solution is to cast the the token type to the proto value
This was per my original suggestion:
tokenType=basic_types_pb2.TokenType(self._token_params.token_type.value)
This works because its taken the token type enum Literal of [0,1] and wrapping it into the proto token type.
or
you can change lines 490 to 494, which in hindsight probably makes more sense
and do
token_type_value = (
self._token_params.token_type.value
if isinstance(self._token_params.token_type, TokenType)
else int(self._token_params.token_type or 0)
)
proto_token_type = basic_types_pb2.TokenType(token_type_value)
so it takes that token type literal and wraps it to proto friendly term
the underlying issue is we lack an easy to proto method for token type and supply type that would mean we can avoid writing all this custom conversions, and probably the type checker is not picking up on the type inference
Then we could just do
tokenType=self._token_params.token_type._to_proto()
and both the code will work (as it currently does) but the type checker will be happy too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently testing if this would work,
My suggestion probably won't work
TypeError: 'EnumTypeWrapper' object is not callable
Not yet sure how to fix underlying issue, which seems to be caused by the type checker
@Pranay22077 can't find a way to fix the issue, let me know if you do! else feel free to start a new issue. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure @exploreriii
That's becoming a little too complex
Will update you about it in some time, after trying other steps
|
Please join our office hour happenign now if you have any questions :) |
Description:
Related issue(s):
Fixes #727
Notes for reviewer:
Checklist