Skip to content

Commit e4312f7

Browse files
asottilesigmavirus24
authored andcommitted
Don't report E701 for variable annotations (#612)
1 parent 30c7c48 commit e4312f7

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

pycodestyle.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@
123123
HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
124124
STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)')
125125
STARTSWITH_TOP_LEVEL_REGEX = re.compile(r'^(async\s+def|def|class|@)')
126+
STARTSWITH_INDENT_STATEMENT_REGEX = re.compile(
127+
r'^\s*({0})'.format('|'.join(s.replace(' ', '\s+') for s in (
128+
'def', 'async def',
129+
'for', 'async for',
130+
'if', 'elif', 'else',
131+
'try', 'except', 'finally',
132+
'with', 'async with',
133+
'class',
134+
'while',
135+
)))
136+
)
126137

127138
# Work around Python < 2.6 behaviour, which does not generate NL after
128139
# a comment which is on a line by itself.
@@ -1004,7 +1015,7 @@ def compound_statements(logical_line):
10041015
break
10051016
if STARTSWITH_DEF_REGEX.match(line):
10061017
yield 0, "E704 multiple statements on one line (def)"
1007-
else:
1018+
elif STARTSWITH_INDENT_STATEMENT_REGEX.match(line):
10081019
yield found, "E701 multiple statements on one line (colon)"
10091020
prev_found = found
10101021
found = line.find(':', found + 1)

testsuite/E90.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pass
99
except:
1010
print 'Whoops'
11-
#: E122 E225 E251 E251 E701
11+
#: E122 E225 E251 E251
1212

1313
# Do not crash if code is invalid
1414
if msg:

testsuite/python3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#!/usr/bin/env python3
2+
from typing import ClassVar, List
23

34

45
# Annotated function (Issue #29)
56
def foo(x: int) -> int:
67
return x + 1
8+
9+
10+
# Annotated variables #575
11+
CONST: int = 42
12+
13+
14+
class Class:
15+
cls_var: ClassVar[str]
16+
17+
def m(self):
18+
xs: List[int] = []

0 commit comments

Comments
 (0)