Skip to content

Process subroutine type annotations #177

@jasonpaulos

Description

@jasonpaulos

Summary

Currently subroutine function type annotations are not processed by the compiler. In order for these annotations to remain truthful (which allows mypy to do proper type checking), they should always be Expr if present.

For example:

from pyteal import *

# acceptable annotations
@Subroutine(TealType.uint64)
def mySubroutineValid(a: Expr, b: Expr) -> Expr:
    return a + b

# unacceptable annotations
@Subroutine(TealType.uint64)
def mySubroutineInvalid(a: TealType.uint64, b: TealType.uint64) -> TealType.uint64:
    return a + b

The second subroutine represents an invalid use of type annotations because the types are not valid at the Python level -- the arguments and return values are PyTeal Exprs, not TealTypes.

Scope

Extend SubroutineDefinition to analyze and remember the type annotations for all arguments and the return type. If annotations are present, they must be Expr (I suppose the return type might be a more specific subclass of Expr, but I don't think this is important enough to allow). If no annotations are present, then assume that all values are annotated with Expr.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions