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

Calling an ABIReturnSubroutine instance returns the type abi.ReturnedValue | Expr #632

Open
jasonpaulos opened this issue Jan 13, 2023 · 0 comments

Comments

@jasonpaulos
Copy link
Contributor

Problem

When calling a subroutine decorated with ABIReturnSubroutine, the Python type annotation of the returned value is abi.ReturnedValue | Expr. Take a look at the definition of ABIReturnSubroutine.__call__:

def __call__(
self, *args: Expr | ScratchVar | abi.BaseType, **kwargs
) -> abi.ReturnedValue | Expr:

The rational behind this behavior is that if an ABIReturnSubroutine returns a value, calling it will return an abi.ReturnedValue; but if the subroutine does not return a valid (has void return type), then it returns a simple Expr.

This union type is problematic for calling code, since abi.ReturnedValue and Expr behave completely differently. As of right now, calling must must cast the value to one of abi.ReturnedValue or Expr for it to pass type checking.

Solution

At the moment I can't think of a good solution for this. ABIReturnSubroutine instances really do return either abi.ReturnedValue or Expr, and I'm not aware of any tricks we can use in the Python type system to make it aware of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants