Calling an ABIReturnSubroutine
instance returns the type abi.ReturnedValue | Expr
#632
Labels
ABIReturnSubroutine
instance returns the type abi.ReturnedValue | Expr
#632
Problem
When calling a subroutine decorated with
ABIReturnSubroutine
, the Python type annotation of the returned value isabi.ReturnedValue | Expr
. Take a look at the definition ofABIReturnSubroutine.__call__
:pyteal/pyteal/ast/subroutine.py
Lines 663 to 665 in 4c716b4
The rational behind this behavior is that if an
ABIReturnSubroutine
returns a value, calling it will return anabi.ReturnedValue
; but if the subroutine does not return a valid (has void return type), then it returns a simpleExpr
.This union type is problematic for calling code, since
abi.ReturnedValue
andExpr
behave completely differently. As of right now, calling must must cast the value to one ofabi.ReturnedValue
orExpr
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 eitherabi.ReturnedValue
orExpr
, and I'm not aware of any tricks we can use in the Python type system to make it aware of this.The text was updated successfully, but these errors were encountered: