Python解包时不允许注释变量类型

Python does not allow annotating the types of variables when unpacking

PEP 526 表示如下:

Note that, although the syntax does allow tuple packing, it does not allow one to annotate the types of variables when tuple unpacking is used.

为什么python解包时不支持变量的类型注解? PS。我必须先注释类型,然后再进行拆包,这很好,只是在拆包时进行注释会更整洁。

PEP 526 的 Rejected/Postponed Proposals section 中有一些关于此的信息:

Allow type annotations for tuple unpacking: This causes ambiguity: it's not clear what this statement means:

x, y: T

Are x and y both of type T, or do we expect T to be a tuple type of two items that are distributed over x and y, or perhaps x has type Any and y has type T? (The latter is what this would mean if this occurred in a function signature.) Rather than leave the (human) reader guessing, we forbid this, at least for now.

该评论似乎暗示最终可能会提出一个更简单的语法的提案,该语法不容易被误解。现在,我们不得不单独注释元组的类型。