Possible to improve typing of the `from_cbor` method?
mpizenberg opened this issue · 4 comments
I’m trying to convert back into a Transaction some cbor hex representing some signed transaction.
Currently, I’m using tx = Transaction.from_cbor(signed_tx_hex), but the type annotations for that from_cbor() function says it returns a CBORSerializable instead of the actual class calling that class method.
As a result, the type checker does not recognize it as a transaction, and isn’t happy about calling tx.id on it. So I can ignore the type checker, but I was wondering if it was possible to improve the typing annotation somehow such that the type checker doesn’t get tripped up on that. Or if there is a fundamental reason why it is CBORSerializable and not the potential subclass being use instead.
Could you please give a minimum example of how you are using the type checker? I think this is fixable and an example of test case would be helpful.
Yes sure, here is the reproducible gist: https://gist.github.com/mpizenberg/771ed233d483a02d23940be579f2a04a
Thanks for the info. Tested the provided script with pyright and the latest commit , and no error is found.
» poetry run pyright main.py
0 errors, 0 warnings, 0 informations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
» cat main.py
from pycardano import Transaction
tx = Transaction.from_cbor("84a500d9010281825820f0e910cc0b48c54d562d99cc5ec5a54e25a449664457e2d157a8425b0565d72300018282583900aff62d714d0c028a034c2793ebf0589b6fb125bd2875a9b24e0086e84a605f26a6492174f97398341875052493695b8930aa56b9e77146a3821a00111958a1581cc627af9fd4828832860a74af935a3903a1f60892fa55ca0d41993dfea14001825839001d737b7461f723d962b5c47092d3ad6d15d6cd2956fe29ad42a6cf6670b46e985fa50328fcb3d80594b6c5c54974a08d2c766a47570bfa361a00183360021a00029831031a04be02270801a100d9010281825820699fcb42601d00a1735f7fd03c7e68adace25339a8444bcb384756b71fdd4a7e5840ce30f2adaa7c73c9679d85c88bdf9343b348fbe9b2946d489b985d92afbfefba259ab23fd557ac0f17b4ddce250a4935b025146c2d28d663c6ab18dc84b1bc0ff5f6")
print("Tx ID: ", tx.id)
Thank you! I can confirm it works for me :)