diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2013-07-04 11:29:12 -0400 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2013-07-04 11:29:12 -0400 |
| commit | d3faf6afab0408d8608d1c73c58359d4e83c8aab (patch) | |
| tree | 6f75c400f1b4f035cd4296e3f25dd936cf657d30 | |
| parent | e2eb1308b124014084b2be111ddcf5ec54795aca (diff) | |
| download | flake8-d3faf6afab0408d8608d1c73c58359d4e83c8aab.tar.gz | |
Fix git hook on python 3
We were expecting strings not bytearrays and so we'll make sure we get
strings. And yes, unicode strings work just fine with this on python 2.
| -rw-r--r-- | flake8/hooks.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/flake8/hooks.py b/flake8/hooks.py index 235f4b9..6687f8c 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -81,6 +81,14 @@ def hg_hook(ui, repo, **kwargs): def run(command): p = Popen(command.split(), stdout=PIPE, stderr=PIPE) (stdout, stderr) = p.communicate() + # On python 3, subprocess.Popen returns bytes objects which expect + # endswith to be given a bytes object or a tuple of bytes but not native + # string objects. This is simply less mysterious than using b'.py' in the + # endswith method. That should work but might still fail horribly. + if hasattr(stdout, 'decode'): + stdout = stdout.decode() + if hasattr(stderr, 'decode'): + stderr = stderr.decode() return (p.returncode, [line.strip() for line in stdout.splitlines()], [line.strip() for line in stderr.splitlines()]) |
