diff options
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-x | pycodestyle.py | 3 |
1 files changed, 3 insertions, 0 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 |