numpy.ndarrayを除くと、
plain
1SequenceNotStr = Union[List[str], Tuple[str, ...]]
で済みそうです。
python
1#!/usr/bin/env python
2from typing import List, Tuple, Union
3
4SequenceNotStr = Union[List[str], Tuple[str, ...]]
5
6
7def a(foo: SequenceNotStr):
8 return len(foo)
9
10
11if __name__ == '__main__':
12 a([1, 2, 3]) # 12
13 a(['a', 'b'])
14 a((1, 2, 3)) # 14
15 a(('a', 'b'))
16 a("abc") # 16
17 a(list("abc"))
結果
plain
1% mypy seq_typing.py
2seq_typing.py:12: error: List item 0 has incompatible type "int"; expected "str"
3seq_typing.py:12: error: List item 1 has incompatible type "int"; expected "str"
4seq_typing.py:12: error: List item 2 has incompatible type "int"; expected "str"
5seq_typing.py:14: error: Argument 1 to "a" has incompatible type "Tuple[int, int, int]"; expected "Union[List[str], Tuple[str, ...]]"
6seq_typing.py:16: error: Argument 1 to "a" has incompatible type "str"; expected "Union[List[str], Tuple[str, ...]]"
7Found 5 errors in 1 file (checked 1 source file)
参考
https://github.com/python/cpython/blob/v3.7.5/Lib/_collections_abc.py#L926
https://github.com/python/cpython/blob/v3.7.5/Lib/_collections_abc.py#L1010