Raise TypeError instead of ValueError if invalid object is passed