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

Fix overloading for call() method #50

Merged
merged 2 commits into from
Nov 22, 2023
Merged

Conversation

sentilesdal
Copy link
Contributor

@sentilesdal sentilesdal commented Nov 22, 2023

In web3.py function construction and execution are separated:

doSomething = deployed_contract.functions.doSomething(x)

result = doSomething.call()

This leads to problems if we want to provide typed return values from call() when doSomething() is overloaded:

doSomething_x = deployed_contract.functions.doSomething(x)
doSomething_xy = deployed_contract.functions.doSomething(x,y)


result_x: int = doSomething_x.call()
result_xy: (int, int) = doSomething_xy.call()

For example, if x and xy versions have the same return signature, then we don't want to declare multiple call() methods. If they do, then we want multple methods, but how do we know which one to call? We can't. We either have to provide multiple return signatures or have doSomething(x) and doSomething(x,y) return different call() methods.

A future improvement would be to change the invocation pattern to:

call_options = CallOptions(block_number=1234)
result = deployed_contract.functions.doSomething(...args, call_options=call_options)

For now, if there are multiple return signatures we simply set the return signature to Any and avoid overloading call() all together. This is probably a very edge case and can be improved in the future.

@sentilesdal sentilesdal marked this pull request as ready for review November 22, 2023 17:01
@sentilesdal sentilesdal merged commit 435485a into main Nov 22, 2023
@sentilesdal sentilesdal deleted the matt-call-overloading branch November 22, 2023 17:10
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.

2 participants