Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Fails to Recognize "coding: utf-8-unix" #29

Open
DevynCJohnson opened this issue May 5, 2019 · 1 comment
Open

Fails to Recognize "coding: utf-8-unix" #29

DevynCJohnson opened this issue May 5, 2019 · 1 comment

Comments

@DevynCJohnson
Copy link

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 ( #12). Although, my fix no longer works in the newest version of flake8-mypy. The fix has already been applied to MyPy itself ( python/mypy#5085 ), but this very helpful Flake8 plugin still lacks the fix.

flake8 --version
3.7.7 (flake8-mypy: 17.8.0, flake8-pyi: 19.3.0, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1, radon: 3.0.1, warn-symbols: 1.1.1) CPython 3.6.7 on Linux

mypy --version
mypy 0.701
@DevynCJohnson
Copy link
Author

DevynCJohnson commented May 12, 2019

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()
 

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant