Skip to content
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

Merged
merged 5 commits into from
Dec 15, 2022

Conversation

linda-le1
Copy link
Contributor

@linda-le1 linda-le1 commented Nov 3, 2022

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 to process_receipt, processLog to process_log, createFilter to create_filter in BaseContractEvent. Change getLogs to getlogs in ContractEvent and AsyncContractEvent.

Todo:

Cute Animal Picture

Screen Shot 2022-11-03 at 12 23 39 AM

@linda-le1 linda-le1 force-pushed the snakecase-contract-event branch 2 times, most recently from 7c6f409 to db12062 Compare December 5, 2022 05:38
@linda-le1 linda-le1 marked this pull request as ready for review December 5, 2022 05:58
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,
Copy link
Collaborator

@fselmo fselmo Dec 5, 2022

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
Copy link
Collaborator

@fselmo fselmo Dec 5, 2022

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.

Copy link
Collaborator

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.

@fselmo
Copy link
Collaborator

fselmo commented Dec 5, 2022

@linda-le1 looks like this needs to be rebased with master as well 👀

docs/contracts.rst Outdated Show resolved Hide resolved
docs/contracts.rst Outdated Show resolved Hide resolved
@pacrob
Copy link
Contributor

pacrob commented Dec 5, 2022

I left one note for the docs anchor title. It also looks like you could remove the Eth.getLogs deprecation notice in docs/web3.eth.rst. Otherwise lookin' good, thanks!

Copy link
Collaborator

@kclowes kclowes left a 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()
Copy link
Collaborator

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
Copy link
Collaborator

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 linda-le1 force-pushed the snakecase-contract-event branch 3 times, most recently from 48670ed to 7c5d04d Compare December 6, 2022 04:47
Copy link
Contributor

@pacrob pacrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link
Collaborator

@kclowes kclowes left a 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.

Copy link
Collaborator

@fselmo fselmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@linda-le1
Copy link
Contributor Author

@kclowes I've consolidated commits - let me know if that looks okay to you. Thanks!

@linda-le1 linda-le1 merged commit e04acaf into ethereum:master Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants