algorand / algorand/pyteal

Support `TealType` subroutine annotations

Open
#178 1 comment 0 reactions 0 assignees View on GitHub
Team Scytale
Dominant language
Python
Stars
288
Forks
138
PR merge metrics
No merged PRs in 30d

Description

## Summary

Some developers use `TealType` annotations in subroutines to declare the expected type of an argument or return value (uint64, bytes, or any). For example:

```python
from pyteal import *

@Subroutine(TealType.uint64)
def mySubroutine(a: TealType.uint64, b: TealType.uint64) -> TealType.uint64:
return a + b
```

Unfortunately these types are not truthful -- the actual arguments and return values must be `Expr`s. So it would be beneficial to be able to express the same constraints, but in a way that preserves the actual type information.

## Scope
Somehow allow `TealType` declarations in a way that does not break the actual Python types.

* One possible solution to this would be to make `Expr` a generic type that takes a `TealType` as a parameter, such as `Expr[TealType.uint64]`. (Note that this would likely require changes to all subclasses of `Expr` so that they can properly handle the fact that it is now a generic type.) Then the example could turn into:
```python
@Subroutine(TealType.uint64)
def mySubroutine(a: Expr[TealType.uint64], b: Expr[TealType.uint64]) -> Expr[TealType.uint64]:
return a + b
```

Regardless of how the `TealType` of arguments and return values are declared, the compiler should also perform type checking every time a subroutine is invoked to verify that the argument being passed to it conform to declared types.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.