
I think that `|` binding more tightly is the better choice here, but I'm having trouble with the behavior in some cases; would bool | (T) -> bool | int parse as bool | Callable[[T], bool | int] ? That makes it seem like `|` has a different precedence in different contexts. Would we require parenthesis here? On Sat, Jun 19, 2021, at 12:29 PM, Guido van Rossum wrote:
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...> _______________________________________________ Typing-sig mailing list -- typing-sig@python.org <mailto:typing-sig%40python.org> To unsubscribe send an email to typing-sig-leave@python.org <mailto:typing-sig-leave%40python.org> https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: rbt@sent.as <mailto:rbt%40sent.as>