[1.7.x] Fixed flake8 warnings.

Backport of 35f46ec7a9 from master