It seems to me like it would be an easy win for making Python type annotations feel more natural to allow the syntax (str, int)
as an alternative to tuple[str, int]
. Tuples are a very important concept in Python, and the syntax seems very natural to me:
def min_max(inputs: list[int]) -> (int, int):
...
As far as I can tell, no parser changes would be required. get_type_hints()
should maybe be changed to convert (T, U, ...)
to tuple[T, U, ...]
.
One slight problem is that (str, int)
cannot be used to signify a tuple bound for a type var in the PEP 695 syntax, because class A[T: (str, int)]
already means that T
is either exactly str
or exactly int
.
Examples from other programming languages
C#
(int, int) MinMax(int[] input)
Rust
fn min_max(input: &[i32]) -> (i32, i32)
Haskell
minMax :: [Int] -> (Int, Int)
Typescript (technically a typed array)
function minMax(input: number[]): [number, number]
Swift (more like a named tuple actually)
func minMax(input: [Int]) -> (min: Int, max: Int)
Zig
fn minMax(input: []const i32) struct { i32, i32 }