Open DevynCJohnson opened 5 years ago
Even if I remove the magic comment, Flake8-MyPy will crash due to an encoding issue.
I found a solution that resolves the crash, but a solution is still needed to make Flake8-MyPy recognize various file-encoding like the other linters.
--- /home/collier/flake8_mypy.py 2019-05-12 08:54:38.430373728 -0500
+++ /usr/local/lib/python3.6/dist-packages/flake8_mypy.py 2019-05-12 08:47:43.138356450 -0500
@@ -185,11 +185,11 @@
# directory.
with TemporaryDirectory(prefix='flake8mypy_') as d:
with NamedTemporaryFile(
- 'w', prefix='tmpmypy_', suffix='.py', dir=d
+ 'wb', prefix='tmpmypy_', suffix='.py', dir=d
) as f:
self.filename = f.name
for line in self.lines:
- f.write(line)
+ f.write(str(line).encode(r'utf-8'))
f.flush()
yield from self._run()
Flake8-MyPy fails to recognize Python scripts that use the magic comment containing
coding: utf-8-unix
as a UTF8 file. This bug has persisted for several versions and I had been fixing it myself ( https://github.com/ambv/flake8-mypy/pull/12). Although, my fix no longer works in the newest version of flake8-mypy. The fix has already been applied to MyPy itself ( https://github.com/python/mypy/pull/5085 ), but this very helpful Flake8 plugin still lacks the fix.