-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Remove AttributeDict method formatters and opt for middleware
#2805
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
Conversation
8b4b4ce to
7ad9bfd
Compare
- ``AttributeDict`` leads to typing complications when properties are accessed via attribute, rather than key / value. This doesn't complicate too much since a user can opt for key / value every time but it isn't ideal to provide an option that breaks typing. Those who wish to turn off all recursive conversion to ``AttributeDict`` can simply remove the ``attrdict_middleware`` (or ``async_attrdict_middleware``) and not worry about possible typing complications. - In order for this to work for async as well, support for ``async_attrdict_middleware` was introduced. This is also now one of the default middlewares for the ``EthereumTesterProvider`` as this was the default behavior achieved via the result formatters.
7ad9bfd to
7231fef
Compare
- fix test_process_params to expect one result formatter - add attribute dict middlewares to sync and async local filter middleware tests - add attrdict middleware check to async http provider test
7231fef to
578b8e8
Compare
22acff8 to
dcb0455
Compare
kclowes
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.
LGTM! Just had one nit in the docs, feel free to take or leave.
| "eth_estimateGas", | ||
| "eth_sendTransaction", | ||
| ): | ||
| fill_default_from = fill_default("from", guess_from, w3) |
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.
That's wild that these are the only methods that need a default from 🤔
pacrob
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.
lgtm!
What was wrong?
AttributeDictleads to typing complications when properties are accessed via attribute, rather than key / value. This doesn't complicate too much since a user can opt for key / value every time but it isn't ideal to provide an option that breaks typing.closes #1656
How was it fixed?
The approach suggested in #1656 does not feel like a great resolution since
NamedTuplewill rename any reserved python keywords to_0,_1,_2, etc... Seeing as JSON-RPC responses commonly have properties likefrom, for example, this would not lead to a very good user experience.AttributeDictconversion was removed from the result formatters and moved back to being only in the middleware. A more inclusive recursive approach was taken to make sure all results get passed through the recursive checks for conversion ofdicttoAttributeDict. Users who wish to turn off all recursive conversion toAttributeDictcan simply remove theattrdict_middleware(orasync_attrdict_middleware) and not worry about possible typing complications.In order for this to work for async as well, support for
async_attrdict_middlewarewas introduced. This is also now one of the default middlewares for theEthereumTesterProvider(andAsyncEthereumTesterProvider) asdict->AttributeDictwas the default behavior, via result formatters, forEthereumTesterProvider.Todo:
attrdict_middleware+async_attrdict_middlewareCute Animal Picture