COMPAT: Python 3. Closes #2131.

Needs a test.