Fix regressions in Python 3 support