I would rather see this split into two functions, with the type check and error handling done in Python. That makes it easier to change without big Cython patches every time.