[1.7.x] Fixed flake8 errors.

Backport of 471fb04a30 from master
[1.7.x] Fixed flake8 warnings introduced in recent commits.

Backport of 79f05616fbf48cf7c205ef17666af0c3d47b3c1e from master