algorand / algorand/pyteal

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

Ouverte
#632 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Team Scytale
Langage dominant
Python
Étoiles
288
Forks
138
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

## 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__`: https://github.com/algorand/pyteal/blob/4c716b44819b9d529df98776423e74dac31883b1/pyteal/ast/subroutine.py#L663-L665

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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.