Skip to content

Commit

Permalink
Merge pull request #613 from sigmavirus24/pr/523
Browse files Browse the repository at this point in the history
Allow all dunder variables above imports
  • Loading branch information
sigmavirus24 authored Jan 26, 2017
2 parents 860369c + 08a6d8a commit 5393c7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
'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.
Expand Down Expand Up @@ -955,6 +956,8 @@ def is_string_literal(line):
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
Expand Down
10 changes: 9 additions & 1 deletion testsuite/E40.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@

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:
Expand Down

0 comments on commit 5393c7d

Please sign in to comment.