From 3a89645ae44375d080110f2ebac0c77501a8af1e Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Wed, 1 Apr 2020 14:08:53 +0900 Subject: [PATCH] fix E402 with __all__ (for #529) --- autopep8.py | 2 +- test/test_autopep8.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/autopep8.py b/autopep8.py index b13165c0..78df5c1f 100755 --- a/autopep8.py +++ b/autopep8.py @@ -1496,7 +1496,7 @@ def has_future_import(source): return cnt + offset + 1 return cnt elif pycodestyle.DUNDER_REGEX.match(line): - continue + return cnt elif any(line.startswith(kw) for kw in allowed_try_keywords): continue elif is_string_literal(line): diff --git a/test/test_autopep8.py b/test/test_autopep8.py index 42baf32b..073de1ee 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -2524,6 +2524,48 @@ def test_e402_import_some_modules(self): ) a = 1 print(os, reader, writer) +""" + with autopep8_context(line) as result: + self.assertEqual(fixed, result) + + def test_e402_with_dunder(self): + line = """\ +__all__ = ["a", "b"] +def f(): + pass +import os +""" + fixed = """\ +import os +__all__ = ["a", "b"] + + +def f(): + pass +""" + with autopep8_context(line) as result: + self.assertEqual(fixed, result) + + def test_e402_with_dunder_lines(self): + line = """\ +__all__ = [ + "a", + "b", +] +def f(): + pass +import os +""" + fixed = """\ +import os +__all__ = [ + "a", + "b", +] + + +def f(): + pass """ with autopep8_context(line) as result: self.assertEqual(fixed, result)