Add missing type-object checks.

Turns various ways to segfault into an appropriate exception.