Skip to content

Commit

Permalink
Merge pull request #530 from hhatto/fix-issue529
Browse files Browse the repository at this point in the history
fix E402 with __all__ var is defined over multiple lines
  • Loading branch information
hhatto committed Apr 2, 2020
2 parents ef15dd5 + 3a89645 commit 7d9c1e1
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 7d9c1e1

Please sign in to comment.