Make OUTPUT_VALID work in Python 3