-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Snakecase contract event methods #2709
Snakecase contract event methods #2709
Conversation
0d9f493
to
cce68a4
Compare
cce68a4
to
d88c129
Compare
7c6f409
to
db12062
Compare
web3/contract.py
Outdated
@@ -1681,7 +1681,7 @@ def getLogs( | |||
|
|||
class AsyncContractEvent(BaseContractEvent): | |||
@combomethod | |||
async def getLogs( | |||
async def get_logs( | |||
self, | |||
argument_filters: Optional[Dict[str, Any]] = None, | |||
fromBlock: Optional[BlockIdentifier] = None, |
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.
I think these can be snake cased... all the way up until we get to building the FilterParams
typed dict.
web3/types.py
Outdated
@@ -149,8 +149,8 @@ class FormattersDict(TypedDict, total=False): | |||
class FilterParams(TypedDict, total=False): | |||
address: Union[Address, ChecksumAddress, List[Address], List[ChecksumAddress]] | |||
blockHash: HexBytes | |||
from_block: BlockIdentifier | |||
to_block: BlockIdentifier | |||
fromBlock: BlockIdentifier |
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.
I think ultimately we make these changes here to camel case and everything else that we can leave snake cased should probably be snake cased. My reasoning is that the method arguments to python functions are expected to be snake cased, by convention. They are just variables up until we construct this TypedDict
. Once we start building the TypedDict
, this is the one translation step that basically says "Ok, we passed everything around using python conventions but now we need to speak to a service that does not use python conventions". The way I see it behaving is these TypedDict
request param classes are the translation layer between python and provider and I think ultimately this is the only place we need the explicit change to camelCase.
I'm curious though if by doing this we run into complications elsewhere. Thoughts @linda-le1 @kclowes @pacrob?
My approach would be to camel case everything that is in the web3/types.py
that is a class making requests to the provider and leave everything else that can be snake cased as snake case.
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.
Yeah, I think I'm in the same boat. Basically anything that goes to/from the node should be camelCase, and everything else should be snaked.
@linda-le1 looks like this needs to be rebased with |
I left one note for the docs anchor title. It also looks like you could remove the |
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.
Awesome! 🚀 I just left one nit pick. Let me/us know if you have questions about when to snake_case
vs. camelCase
based on @fselmo's comment.
@@ -19,12 +19,12 @@ def test_contract_getLogs_all( | |||
txn_hash = contract.functions.logNoArgs(event_id).transact() |
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.
I can't comment on the actual line, but looks like the test name on line 10 needs a snake case: test_contract_get_logs_all
web3/types.py
Outdated
@@ -149,8 +149,8 @@ class FormattersDict(TypedDict, total=False): | |||
class FilterParams(TypedDict, total=False): | |||
address: Union[Address, ChecksumAddress, List[Address], List[ChecksumAddress]] | |||
blockHash: HexBytes | |||
from_block: BlockIdentifier | |||
to_block: BlockIdentifier | |||
fromBlock: BlockIdentifier |
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.
Yeah, I think I'm in the same boat. Basically anything that goes to/from the node should be camelCase, and everything else should be snaked.
48670ed
to
7c5d04d
Compare
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!
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 too! Thanks @linda-le1!
Edit: looks like we need to clean up some commits. I think it would be clearest to have one commit for each of the snake case-s: getLog
-> get_log
, processReciept
-> process_receipt
, createFilter
-> create_filter
, and the kwargs, but could also see just squashing into one if that's too complicated.
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!
1753aa3
to
c1137a4
Compare
@kclowes I've consolidated commits - let me know if that looks okay to you. Thanks! |
c1137a4
to
38e04a1
Compare
What was wrong?
Inherited javascript syntax. This PR does not include a deprecation step, intended for v6.
Related to Issue #2598
How was it fixed?
Changed
processReceipt
toprocess_receipt
,processLog
toprocess_log
,createFilter
tocreate_filter
inBaseContractEvent
. ChangegetLogs
togetlogs
inContractEvent
andAsyncContractEvent
.Todo:
Cute Animal Picture