Fix a syntax error in the generated file.

Also fix some code paths that had some namespace errors,
as well as make flake8 a bit happier.

Ticket: #4929