summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Cousineau <eric.cousineau@tri.global>2019-01-30 10:54:40 -0500
committerEric Cousineau <eric.cousineau@tri.global>2019-01-30 12:15:25 -0500
commiteba7f0f7847762bae419e366354bb30e6230daeb (patch)
treefb91d13c94efa91142bad51c126f5600df523ca7
parent1f8d5ca1a1ede54e6d7b67693b36b209b940573c (diff)
downloadpep8-eba7f0f7847762bae419e366354bb30e6230daeb.tar.gz
E402: Add "if" statement to allowed keywords
-rwxr-xr-xpycodestyle.py3
-rw-r--r--testsuite/E40.py5
2 files changed, 7 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 278bf12..68d4140 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -1067,7 +1067,8 @@ def module_imports_on_top_of_file(
line = line[1:]
return line and (line[0] == '"' or line[0] == "'")
- allowed_keywords = ('try', 'except', 'else', 'finally', 'with')
+ allowed_keywords = (
+ 'try', 'except', 'else', 'finally', 'with', 'if')
if indent_level: # Allow imports in conditional statement/function
return
diff --git a/testsuite/E40.py b/testsuite/E40.py
index 6d123b1..041ffb3 100644
--- a/testsuite/E40.py
+++ b/testsuite/E40.py
@@ -40,6 +40,11 @@ with warnings.catch_warnings():
import foo
import bar
+#: Okay
+if False:
+ import foo
+
+import bar
#: E402
VERSION = '1.2.3'