use isinstance and TypeError

This isn't high priority, but we should really be using 'isinstance' instead of
'type'

http://stackoverflow.com/questions/1549801/differences-between-isinstance-and-type-in-python

Also we should raise a TypeError if the type isn't correct.

There is a tentative fix for the py3 special case in there too, but alas, I
have no such interpreter.

Maybe using travisCI, which IIRC supports py3, would be a good way to check for
such stuff earlier..