This makes me curious; wouldn't it be possible to write an automated linter or static code analyzer that would catch and automatically fix these issues?
In Node environment, I think that I would be able to come up with an ESLint plugin. Doesn't Python ecosystem have something similar?