Convert isinstance assertions to TypeErrors.

Using assert statements can cause subtle bugs when Python
interpreter invoked with the -O option..

See https://code.djangoproject.com/ticket/23924 for an example report.
Merge pull request #549 from berkerpeksag/remove-asserts

Convert isinstance assertions to TypeErrors.