Python - 如何键入提示调用 returns 一个元组的函数?

Python - how to type hint calling a function that returns a tuple?

今天我很惊讶地发现以下在 Python 中生成错误(我使用的是 Python 3.8)

from typing import Tuple, List, Dict

def main():
    
    my_list: List, my_dict: Dict = my_function()   # this is the line I'm asking about

    print(my_list)
    print(my_dict)

# end function

def my_function() -> Tuple[List, Dict]:
    my_list = [1, 2, 3]
    my_dict = { 'one': 1, 'two': 2}
    return my_list, my_dict
# end function

if __name__ == '__main__':
    main()

结果:

$ python3 data/scratchpad2.py 
  File "data/scratchpad2.py", line 7
    my_list: List, my_dict: Dict = my_function()
                 ^
SyntaxError: invalid syntax

如果我去掉函数调用处的类型提示,一切都会按预期进行。我只是没有输入正确的语法,还是真的不允许这样做?如果不允许,当从函数接收元组时如何使用类型提示?

According to PEP-0526, you should annotate the types first, then do the unpacking

a: int
b: int
a, b = t