When using Flake8 (with Flake8-Mypy) on Python scripts containing comments with Unicode comments, Flake8 crashes with a UnicodeEncodeError. The suggested code in my commit appears to resolve the issue without side-effects.
I don't understand how the current behavior (which sets encoding to 'utf8' in the NamedTemporaryFile) is any worse than your suggested encoding of every line to utf8 and writing in binary.
When using Flake8 (with Flake8-Mypy) on Python scripts containing comments with Unicode comments, Flake8 crashes with a UnicodeEncodeError. The suggested code in my commit appears to resolve the issue without side-effects.