algorand / algorand/pyteal

Settle on Best Practice for Union / Optional Type Annotations

Đang mở
#619 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
new-feature-request Team Scytale
Ngôn ngữ chính
Python
Star
288
Fork
138
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.