Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix E402 with __all__ var is defined over multiple lines #530

Merged
merged 1 commit into from Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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