3

How can I add typing to a destructuring assignment in python 3?

This example assignment, does not work because a:int, b:int = return_tuple() is not valid:

from typing import Tuple

def return_tuple() -> Tuple[int, int]:
    return 0, 0
        
a:int, b:int = return_typle()

We can see this is not valid because running mypy returns

foo.py:7: error: invalid syntax
Found 1 error in 1 file (checked 1 source file)
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
bytesandwich
  • 373
  • 2
  • 10
  • 3
    Does this answer your question? [Type hints when unpacking a tuple?](https://stackoverflow.com/questions/52082939/type-hints-when-unpacking-a-tuple) – tfw Nov 25 '20 at 08:36

0 Answers0