[1.7.x] Fixed flake8 warnings.

Backport of 9a922dcad1 from master