Я написал функцию Python, которая обрабатывает список int или список списков int, т.е. [1,2,3]
или [[1,2],[3,4]
, следующим образом:
from typing import Sequence, Union
IntSeq = Sequence[int]
def foo(a: Union[IntSeq, Sequence[IntSeq]]):
if isinstance(a, Sequence) and isinstance(a[0], int):
# here type of a equals IntSeq
b: IntSeq = a
Однако mypy сообщил мне об ошибке ниже:
$ mypy bar.py
test.py:6: error: Incompatible types in assignment (expression has type "Union[Sequence[int], Sequence[Sequence[int]]]", variable has type "Sequence[int]")
Как пропустить эту ошибку?