Jelle Zijlstra wrote:
I like this too. A practical issue is that list[(a, b)] and list[a, b] look
the same to the compiler, but they would mean very different things. It's not obvious how to fix this in a backward-compatible way.
I think it looks much cleaner, and if there isn't any drawbacks to adding this syntax, I'd love to work on bringing this to life.
Restricting it to only the top level of a return type annotation should do the trick!
Such that:
def f() -> (X, Y, Z): ...
is interpreted as tuple[X, Y, Z], but:
def f(x: (X, Y, Z)) -> None: ... def f() -> Union[int, (X, Y, Z)]: ... def f() -> list[(X, Y, Z)]: ...
Are not considered as tuple[...]