Repository: hylang/hy

Issue:
flake8 warnings
```
hy/completer.py:52:1: E402 module level import not at top of file
hy/completer.py:53:1: E402 module level import not at top of file
hy/completer.py:55:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:30:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:31:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:32:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:33:1: E402 module level import not at top of file
tests/test_bin.py:140:35: W503 line break before binary operator
hy/compiler.py:696:13: W503 line break before binary operator
```



Discussion:
New flake8 version? Since these does not show up in master.

This appears to be due to changes in version [1.6](https://github.com/jcrocholl/pep8/blob/dcfdfda785/CHANGES.txt#L29-82) of `pep8` (a dependency of flake8), released ten days ago.

``` bash
# downgrading to the version just prior to 1.6.0 made the failures go away---
(hy) zmd@ExpectedReturn:~/Code/hy/hy$ python -c "import pep8; print(pep8.__version__)"
1.5.7
(hy) zmd@ExpectedReturn:~/Code/hy/hy$ flake8 hy tests
(hy) zmd@ExpectedReturn:~/Code/hy/hy$ echo $?
0
# but they're present when we upgrade back
(hy) zmd@ExpectedReturn:~/Code/hy/hy$ pip install pep8==1.6.0
Collecting pep8==1.6.0
  Using cached pep8-1.6.0-py2.py3-none-any.whl
Installing collected packages: pep8
  Found existing installation: pep8 1.5.7
    Uninstalling pep8-1.5.7:
      Successfully uninstalled pep8-1.5.7

Successfully installed pep8-1.6.0
(hy) zmd@ExpectedReturn:~/Code/hy/hy$ flake8 hy tests
hy/completer.py:52:1: E402 module level import not at top of file
hy/completer.py:53:1: E402 module level import not at top of file
hy/completer.py:55:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:30:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:31:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:32:1: E402 module level import not at top of file
tests/compilers/test_compiler.py:33:1: E402 module level import not at top of file
(hy) zmd@ExpectedReturn:~/Code/hy/hy$ echo $?
1
```


Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -692,8 +692,9 @@ def compile_eval(self, expr):
         expr.pop(0)
 
         ret = self.compile(HyExpression(
-            [HySymbol("hy_eval")] + expr + [HyExpression([HySymbol("locals")])]
-            + [HyString(self.module_name)]).replace(expr)
+            [HySymbol("hy_eval")] + expr +
+            [HyExpression([HySymbol("locals")])] +
+            [HyString(self.module_name)]).replace(expr)
         )
 
         ret.add_imports("hy.importer", ["hy_eval"])
diff --git a/hy/completer.py b/hy/completer.py
--- a/hy/completer.py
+++ b/hy/completer.py
@@ -25,11 +25,15 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+import contextlib
 import os
 import re
 import sys
-from contextlib import contextmanager
-from hy._compat import string_types
+
+import hy.macros
+import hy.compiler
+from hy._compat import builtins, string_types
+
 
 docomplete = True
 
@@ -49,12 +53,6 @@
     readline_bind = "tab: complete"
 
 
-import hy.macros
-import hy.compiler
-
-from hy._compat import builtins
-
-
 class Completer(object):
 
     def __init__(self, namespace={}):
@@ -129,7 +127,7 @@ def complete(self, text, state):
             return None
 
 
-@contextmanager
+@contextlib.contextmanager
 def completion(completer=None):
     delims = "()[]{} "
     if not completer:


Test patch:
diff --git a/tests/compilers/test_compiler.py b/tests/compilers/test_compiler.py
--- a/tests/compilers/test_compiler.py
+++ b/tests/compilers/test_compiler.py
@@ -22,16 +22,16 @@
 import ast
 import sys
 
-if sys.version_info[0] <= 2 and sys.version_info[1] <= 6:
-    import unittest2 as unittest
-else:
-    import unittest
-
 from hy import compiler
 from hy.models.expression import HyExpression
 from hy.models.list import HyList
 from hy.models.symbol import HySymbol
 
+if sys.version_info[0] <= 2 and sys.version_info[1] <= 6:
+    import unittest2 as unittest
+else:
+    import unittest
+
 
 class CompilerTest(unittest.TestCase):
 
diff --git a/tests/test_bin.py b/tests/test_bin.py
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -136,8 +136,7 @@ def test_hy2py():
                     continue
                 else:
                     i += 1
-                    ret = run_cmd("hy2py -s -a "
-                                  + os.path.join(dirpath, f))
+                    ret = run_cmd("hy2py -s -a " + os.path.join(dirpath, f))
                     assert ret[0] == 0, f
                     assert len(ret[1]) > 1, f
                     assert len(ret[2]) == 0, f