basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

Change up the game with how tuples are denoted

Open KotlinIsland opened this issue 2 years ago • 0 comments

Variadic tuples should be like tuple[int] Variadic tuples could be denoted as (*int,) Fixed length tuples should be (int,)

There is a question about if tuple[int, ...] should still be supported, or if a VariadicTuple should be invented. Because I want ... syntax to represent unbound generics (#30).

Maybe ... denotion for unbound generics doesn't work for tuple and you have to use Unbound or something.

Problem 🔥

A tuple in an index is unwrapped

x[1, 2] == x[(1, 2)]

So you would be forced to double wrap tuple literal types in generics:

a: list[(int, int),] = [(1, 2)]

Hmm, the trailing comma isn't the end of the world, but it would certainly lead to mistakes...

We can add mypy inspections to enforce strictly specifying the trailing comma.

KotlinIsland avatar Feb 02 '23 01:02 KotlinIsland