-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Make AsyncWeb3 Generic #3761
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
Make AsyncWeb3 Generic #3761
Conversation
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.
Thanks @aleexharris! This looks great and is definitely the preferred / correct approach. Much appreciated 🙏🏼.
I made some minor adjustments and some cleanup in the last commits here. @kclowes I'll let you sign off on this but lgtm 👍🏼
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.
Thanks for the PR, nice catch! I'd prefer to keep anything not related to the bug (casing/commas/whitespace/etc. changes) out of this PR if possible. I'm happy to update tomorrow or leave it for you, whatever you'd prefer!
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.
Ah, a lot of what I thought was random changes was black fixups. LGTM!
* fix: Made function params Optional, as None is the default input * feat: Made AsyncWeb3 class Generic to fix type errors when importing Web3 * refactor: remove unnecessary noqa: E501 uses * fix: remove `Optional` where it isn't optional * fix: Use `Optional` where appropriate * chore: add newsfragment for ethereum#3761 * fix: Removed where it isn't optional * Remove unnecessary changes --------- Co-authored-by: fselmo <fselmo2@gmail.com> Co-authored-by: kclowes <kclowes@users.noreply.github.com>
* fix: Made function params Optional, as None is the default input * feat: Made AsyncWeb3 class Generic to fix type errors when importing Web3 * refactor: remove unnecessary noqa: E501 uses * fix: remove `Optional` where it isn't optional * fix: Use `Optional` where appropriate * chore: add newsfragment for ethereum#3761 * fix: Removed where it isn't optional * Remove unnecessary changes --------- Co-authored-by: fselmo <fselmo2@gmail.com> Co-authored-by: kclowes <kclowes@users.noreply.github.com>
* Make AsyncWeb3 Generic (ethereum#3761) * fix: Made function params Optional, as None is the default input * feat: Made AsyncWeb3 class Generic to fix type errors when importing Web3 * refactor: remove unnecessary noqa: E501 uses * fix: remove `Optional` where it isn't optional * fix: Use `Optional` where appropriate * chore: add newsfragment for ethereum#3761 * fix: Removed where it isn't optional * Remove unnecessary changes --------- Co-authored-by: fselmo <fselmo2@gmail.com> Co-authored-by: kclowes <kclowes@users.noreply.github.com> * Compile release notes for v7.14.0 * Bump version: 7.13.0 → 7.14.0 * Align isort skip path --------- Co-authored-by: Alex Harris <122488678+aleexharris@users.noreply.github.com> Co-authored-by: fselmo <fselmo2@gmail.com> Co-authored-by: kclowes <kclowes@users.noreply.github.com> Co-authored-by: Shresth79 <shresthpatelshrepate@gmail.com>
AsyncWeb3 Generic Type Fix
Problem
Closes #3759
Previously, when using
AsyncWeb3with a specific provider likeAsyncHTTPProvider, type checkers (I found this issue using ty) could not resolve provider-specific methods because theAsyncWeb3.providerproperty was typed as returningAsyncBaseProviderrather than the concrete provider type.This caused type checking errors like:
Solution
The
AsyncWeb3class has been made generic using aTypeVarbound toAsyncBaseProvider. This allows type checkers to infer the specific provider type and resolve provider-specific methods correctly. This is purely a type annotation change with no impact on runtime behavior and is fully backwards compatible. All tests pass.Implementation Changes
TypeVarbound toAsyncBaseProvider:AsyncWeb3inherit fromGeneric[AsyncProviderT]providerparameter and property to useAsyncProviderTExample
The provider type is automatically inferred from the constructor argument (or can be explicitly annotated)
Todo:
Cute Animal Picture