Python 3.6 对此元组示例没有问题:
# tpl is a tuple. Each entry consists of a tuple with two entries. The first
# of those is a tuple of two strings. The second one is a tuple of tuples with
# three strings.
tpl = (
(('a', 'b'), (('1', '2', '3'), ('4', '5', '6'))),
(('c', 'd'), (('7', '8', '9'),)),
)
for first_tuple, second_tuple in tpl:
str1, str2 = first_tuple
print(str1, str2)
for str1, str2, str3 in second_tuple:
print(' ', str1, str2, str3)
print()
输出:
a b
1 2 3
4 5 6
c d
7 8 9
但是 mypy 0.511 似乎会感到困惑并报告错误:
ttpl.py:13: error: Iterable expected
ttpl.py:13: error: "object" has no attribute "__iter__"; maybe "__str__"?
我能做些什么来帮助 mypy 了解发生了什么?