algorand / algorand/pyteal

Settle on Best Practice for Union / Optional Type Annotations

Abierto
#619 5 comentarios 0 reacciones 0 asignados Ver en GitHub
new-feature-request Team Scytale
Lenguaje dominante
Python
Estrellas
288
Forks
138
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## Problem

[PEP 604](https://peps.python.org/pep-0604/) allows the pipe symbol (`|`) to annotate unions of types. In particular:

`X | Y` $\equiv$ `Union[X,Y]`

and

`X | None` $\equiv$ `Optional[X]`

However, type forwarding does not work with this new capability. I.e. `"Xtype" | Y` doesn't work (though `"Xtype | Y"` does actually work).

Currently our repo is inconsistent when it comes to union types.

## Solution

We should settle on a best practice for such annotations, change all usages to adhere to the best practice, and add it to our [style guide](https://github.com/algorand/pyteal/blob/master/CONTRIBUTING.md#code-guidelines).

I propose that we disallow `|` because of its incompatibility with forwarded types. But I'm open to discussion and don't have a strong opinion, except that we should have _some_ convention.

## Dependencies

None

## Urgency

Very low

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.