Skip to content

Commit

Permalink
fix E402 with __all__ (for #529)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Apr 1, 2020
1 parent ef15dd5 commit 3a89645
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autopep8.py
Expand Up @@ -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):
Expand Down
42 changes: 42 additions & 0 deletions test/test_autopep8.py
Expand Up @@ -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)
Expand Down

0 comments on commit 3a89645

Please sign in to comment.