[1.7.x] Fixed flake8 warnings.

Backport of 6f59d29158 from master