Fix Python 3 support

The fix itself was a tiny change, but I added some tests to ensure that it didn't break things.