summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <sigmavirus24@users.noreply.github.com>2017-01-25 19:50:42 -0600
committerGitHub <noreply@github.com>2017-01-25 19:50:42 -0600
commit5393c7d133949ef563999f0df1ac0a3af760e0fe (patch)
tree25e46061c7243c8a806c9b88a8e68f642ff3d228
parent860369c7e8178779fdc33fb74c2d12b2674c6762 (diff)
parent08a6d8a3c69ebef67172a70db6581469285a295b (diff)
downloadpep8-5393c7d133949ef563999f0df1ac0a3af760e0fe.tar.gz
Merge pull request #613 from sigmavirus24/pr/523
Allow all dunder variables above imports
-rwxr-xr-xpycodestyle.py3
-rw-r--r--testsuite/E40.py10
2 files changed, 12 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index e0df43f..96d2da3 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -134,6 +134,7 @@ STARTSWITH_INDENT_STATEMENT_REGEX = re.compile(
'while',
)))
)
+DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ')
# Work around Python < 2.6 behaviour, which does not generate NL after
# a comment which is on a line by itself.
@@ -955,6 +956,8 @@ def module_imports_on_top_of_file(
if line.startswith('import ') or line.startswith('from '):
if checker_state.get('seen_non_imports', False):
yield 0, "E402 module level import not at top of file"
+ elif re.match(DUNDER_REGEX, line):
+ return
elif any(line.startswith(kw) for kw in allowed_try_keywords):
# Allow try, except, else, finally keywords intermixed with imports in
# order to support conditional importing
diff --git a/testsuite/E40.py b/testsuite/E40.py
index 18ac73a..f9a18fc 100644
--- a/testsuite/E40.py
+++ b/testsuite/E40.py
@@ -11,11 +11,19 @@ from foo.bar.yourclass import YourClass
import myclass
import foo.bar.yourclass
-#: E402
+#: Okay
__all__ = ['abc']
import foo
#: Okay
+__version__ = "42"
+
+import foo
+#: Okay
+__author__ = "Simon Gomizelj"
+
+import foo
+#: Okay
try:
import foo
except ImportError: