diff options
author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2019-09-25 17:47:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-25 17:47:26 -0500 |
commit | b93125aa67ce201e9194445472fcf54a5a925db9 (patch) | |
tree | 341de031329a799d6b79d7482a35de9dc24cd938 /pycodestyle.py | |
parent | 9726e10004e5615c432f126530ee0540b9903f6e (diff) | |
parent | dd6268c488ec6ab23188f31f7a1d345a8e114cbe (diff) | |
download | pep8-b93125aa67ce201e9194445472fcf54a5a925db9.tar.gz |
Merge pull request #834 from EricCousineau-TRI/issue/833
E402: Add "with" statement to allowed keywords
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-x | pycodestyle.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index 4ade087..6ad5456 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1073,7 +1073,8 @@ def module_imports_on_top_of_file( line = line[1:] return line and (line[0] == '"' or line[0] == "'") - allowed_try_keywords = ('try', 'except', 'else', 'finally') + allowed_keywords = ( + 'try', 'except', 'else', 'finally', 'with', 'if', 'elif') if indent_level: # Allow imports in conditional statement/function return @@ -1087,9 +1088,9 @@ def module_imports_on_top_of_file( 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 + elif any(line.startswith(kw) for kw in allowed_keywords): + # Allow certain keywords intermixed with imports in order to + # support conditional or filtered importing return elif is_string_literal(line): # The first literal is a docstring, allow it. Otherwise, report |