Skip to content

Commit 5246b9e

Browse files
authored
Merge pull request #1247 from PyCQA/space-after-decorator
add new error E204 for whitespace after decorator @
2 parents d343c39 + 3cedd4c commit 5246b9e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/intro.rst

+2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ This is the current list of error and warning codes:
262262
+------------+----------------------------------------------------------------------+
263263
| E203 | whitespace before ',', ';', or ':' |
264264
+------------+----------------------------------------------------------------------+
265+
| E204 | whitespace after decorator '@' |
266+
+------------+----------------------------------------------------------------------+
265267
+------------+----------------------------------------------------------------------+
266268
| E211 | whitespace before '(' |
267269
+------------+----------------------------------------------------------------------+

pycodestyle.py

+7
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
121121
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
122122
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({][ \t]|[ \t][\]}),;:](?!=)')
123+
WHITESPACE_AFTER_DECORATOR_REGEX = re.compile(r'@\s')
123124
WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
124125
COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)'
125126
r'\s*(?(1)|(None|False|True))\b')
@@ -438,6 +439,9 @@ def extraneous_whitespace(logical_line):
438439
E203: if x == 4: print x, y; x, y = y , x
439440
E203: if x == 4: print x, y ; x, y = y, x
440441
E203: if x == 4 : print x, y; x, y = y, x
442+
443+
Okay: @decorator
444+
E204: @ decorator
441445
"""
442446
line = logical_line
443447
for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line):
@@ -451,6 +455,9 @@ def extraneous_whitespace(logical_line):
451455
code = ('E202' if char in '}])' else 'E203') # if char in ',;:'
452456
yield found, f"{code} whitespace before '{char}'"
453457

458+
if WHITESPACE_AFTER_DECORATOR_REGEX.match(logical_line):
459+
yield 1, "E204 whitespace after decorator '@'"
460+
454461

455462
@register_check
456463
def whitespace_around_keywords(logical_line):

testing/data/E20.py

+17
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,21 @@
7575
x, y = y, x
7676
a[b1, :] == a[b1, ...]
7777
b = a[:, b1]
78+
#: E204:1:2
79+
@ decorator
80+
def f():
81+
pass
82+
#: E204:1:2
83+
@ decorator
84+
def f():
85+
pass
86+
#: E204:1:2
87+
@ decorator
88+
def f():
89+
pass
90+
#: E204:2:6
91+
if True:
92+
@ decorator
93+
def f():
94+
pass
7895
#:

0 commit comments

Comments
 (0)