
On Sat, Jun 19, 2021 at 8:26 AM Eric Traut <eric@traut.com> wrote:
Thanks for writing the document. It's a very helpful step forward.
Indeed. One thing that occurs to me is that all of the syntax proposals create
ambiguities when the `->` operator is combined with `|` (union). The order of precedence between `->` and `|` would need to be established and documented, and parentheses would need to be supported to override the normal precedence.
Take this example:
```python # Does this mean `Union[Callable[[int], int], str]` or `Callable[[int], Union[int, str]]`? (int) -> int | str
# With parentheses, it is unambiguous. ((int) -> int) | str (int) -> (int | str) ```
For what it's worth, TypeScript chose to bind `|` more tightly. If we were to adopt this precedent, `(int) -> int | str` would imply `(int) -> (int | str)`.
I think we should do the same, because in the one other context where '->' is used ('def f(...) -> ...'), '}' also binds more tightly than '->'. Since this usage is so closely coupled to function types I think we have little choice in the matter, else we'd just confuse users. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>