-, , , if isinstance(x, list), type(x). , , (. isinstance() type() python).
-, , x ? ? - ? Sequence ? , np.array? Python , "duck typing" ; , .
:
from collections import Sequence
def some_func(x, n):
if not isinstance(x, (Sequence, np.ndarray)):
raise TypeError('x must be a sequence or numpy array')
x = np.ndarray(x)
if x.size != n ** 2:
raise ValueError('x must be {} long'.format(n ** 2))
...
a TypeError ( x n), ValueError (x - , ), , AssertionError, .