Skip to content

Commit e3ec49a

Browse files
committed
Replace the IDENTIFIER_REGEX with the isidentifier function
1 parent f87bf23 commit e3ec49a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pep8.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
113113
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
114114
LAMBDA_REGEX = re.compile(r'\blambda\b')
115-
IDENTIFIER_REGEX = re.compile('\s*[^.[\]]+\s=')
116115
HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
117116

118117
# Work around Python < 2.6 behaviour, which does not generate NL after
@@ -923,10 +922,11 @@ def compound_statements(logical_line):
923922
if ((before.count('{') <= before.count('}') and # {'a': 1} (dict)
924923
before.count('[') <= before.count(']') and # [1:2] (slice)
925924
before.count('(') <= before.count(')'))): # (annotation)
926-
if LAMBDA_REGEX.search(before):
927-
if IDENTIFIER_REGEX.match(before):
928-
yield 0, ("E731 do not assign a lambda expression, use a"
929-
" def")
925+
lambda_kw = LAMBDA_REGEX.search(before)
926+
if lambda_kw:
927+
before = line[:lambda_kw.start()].rstrip()
928+
if before[-1:] == '=' and isidentifier(before[:-1].strip()):
929+
yield 0, "E731 do not assign a lambda expression, use a def"
930930
break
931931
if before.startswith('def '):
932932
yield 0, "E704 multiple statements on one line (def)"

testsuite/E73.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#: Okay
99
f = object()
1010
f.method = lambda: 'Method'
11-
#: Okay
11+
1212
f = {}
1313
f['a'] = lambda x: x ** 2
14-
#: Okay
14+
1515
f = []
1616
f.append(lambda x: x ** 2)
17-
#: Okay
17+
1818
lambda: 'no-op'

0 commit comments

Comments
 (0)