Allow Omission of Outer Tuple in Function Return Type Annotations
This requests extending Python’s type annotation syntax to permit omitting the explicit tuple[] wrapper for function return type annotations representing tuples. Specifically, it would make -> int, int a valid and semantically equivalent alternative to -> tuple[int, int].
# Fails
def f() -> int, int: # Syntax error in current Python
return 1, 1
Python has allowed omitting parentheses for tuples in return statements and assignments (e.g., a, b = 1, 2). Extending this to return type annotations maintains consistency across the language.
Valid Use Cases
| Proposed Annotation | Equivalent Current Annotation | Use Case |
|---|---|---|
def f() -> int, int |
def f() -> tuple[int, int] |
Basic 2-element tuple return |
def f() -> str, float, bool |
def f() -> tuple[str, float, bool] |
Multi-element tuple |
def f() -> int, |
def f() -> tuple[int,] |
Single-element tuple (matches return 1,) |
def f() -> (int, str), float |
def f() -> tuple[tuple[int, str], float] |
Nested tuples (inner parentheses retained) |
def f() -> int, ... |
def f() -> tuple[int, ...] |
Variable-length tuple (ellipsis) |