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
Uses Self
Type in contract factory methods
#2997
Conversation
I'll leave this open in case you want to try a different solution that maintains compatibility. |
Thanks for reviewing the PR. |
OK, dug in a bit further. You are correct that we can use Once we get that in, I'll come back and pull this in. Thank you! |
1. Uses the recently added `Self` Type for better type inference whenever Contract is subclassed 2. Fixes the return type of `Contract.factory` to indicate that a class is returned instead of an instance thereof
Fixes / ignores any warnings that appeared as a result
Great point, I did not catch that. |
241aa75
to
2792dd4
Compare
I've branched it in #3001 and CI is passing there, so we can just use that if we can't get it to run here. |
Thanks for this, @konichuvak ! Your original commits are merged in #3001 |
What was wrong?
Return type of
Contract.factory()
is erroneously annotated as"Contract"
instead ofType["Contract"]
Even once we fix the error above, type annotation for subclasses of
Contract
are brokenHow was it fixed?
Self
Type was added in Python 3.11 which solves this problem of underspecified return types of constructor methods for subclasses.Todo:
Cute Animal Picture