Backport PR #4758 - fixes for Python 3.4.