1

Is there any way to add types to values extracting from Tuple from function like below?

from typing import Tuple

def f() -> Tuple[int, int, int]: 
    return 1, 2, 3

Desired way:

i: int, j: int, n: int = f()

What I already tried:

i: int, j: int, n: int = f()
# SyntaxError: invalid syntax
i: int, j, n = f()
# SyntaxError: invalid syntax
i, j, n: int = f()
# SyntaxError: invalid syntax
(i: int), (j: int), (n: int) = f()
# SyntaxError: invalid syntax
Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
mikolaj semeniuk
  • 2,030
  • 15
  • 31
  • I'm unclear why you would need to type annotate the return value. At least in Pycharm, it can already infer that the return type of `f()[0]` is int. – rv.kvetch Oct 12 '21 at 19:42
  • 1
    Unluckily Jupyter notebook cannot infer return type that's why I'm used to add types manually. – mikolaj semeniuk Oct 12 '21 at 19:47

0 Answers0