Skip to content

Possible to improve typing of the from_cbor method? #442

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

Open
mpizenberg opened this issue May 2, 2025 · 2 comments
Open

Possible to improve typing of the from_cbor method? #442

mpizenberg opened this issue May 2, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@mpizenberg
Copy link

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.

@cffls cffls added the enhancement New feature or request label May 2, 2025
@cffls
Copy link
Collaborator

cffls commented May 3, 2025

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.

@mpizenberg
Copy link
Author

Yes sure, here is the reproducible gist: https://gist.github.com/mpizenberg/771ed233d483a02d23940be579f2a04a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants