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))
What is the best way to check that passed parameters are valid in Python?