How to get Mypy to realize that sorting two ints gives back two ints
问题 My code is as follows: from typing import Tuple a: Tuple[int, int] = tuple(sorted([1, 3])) Mypy tells me: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int]") What am I doing wrong? Why can't Mypy figure out that the sorted tuple will give back exactly two integers? 回答1: The call to sorted produces a List[int] which carries no information about length. As such, producing a tuple from it also has no information about the length. The