algorand / algorand/pyteal

Support `TealType` subroutine annotations

Offen
#178 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Team Scytale
Vorherrschende Sprache
Python
Sterne
288
Forks
138
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.