summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-12-16 01:38:56 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-12-16 01:38:56 +0100
commite3ec49a97d8b84a3daa548574f790b6d6a6f015f (patch)
treef5b75da5f54f6002ada5a53b158c7d0f31e794ec
parentf87bf238186741169a62ee0e9827068c209bed6f (diff)
downloadpep8-e3ec49a97d8b84a3daa548574f790b6d6a6f015f.tar.gz
Replace the IDENTIFIER_REGEX with the isidentifier function
-rwxr-xr-xpep8.py10
-rw-r--r--testsuite/E73.py6
2 files changed, 8 insertions, 8 deletions
diff --git a/pep8.py b/pep8.py
index 87e2881..cbd3068 100755
--- a/pep8.py
+++ b/pep8.py
@@ -112,7 +112,6 @@ COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type'
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
LAMBDA_REGEX = re.compile(r'\blambda\b')
-IDENTIFIER_REGEX = re.compile('\s*[^.[\]]+\s=')
HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
# Work around Python < 2.6 behaviour, which does not generate NL after
@@ -923,10 +922,11 @@ def compound_statements(logical_line):
if ((before.count('{') <= before.count('}') and # {'a': 1} (dict)
before.count('[') <= before.count(']') and # [1:2] (slice)
before.count('(') <= before.count(')'))): # (annotation)
- if LAMBDA_REGEX.search(before):
- if IDENTIFIER_REGEX.match(before):
- yield 0, ("E731 do not assign a lambda expression, use a"
- " def")
+ lambda_kw = LAMBDA_REGEX.search(before)
+ if lambda_kw:
+ before = line[:lambda_kw.start()].rstrip()
+ if before[-1:] == '=' and isidentifier(before[:-1].strip()):
+ yield 0, "E731 do not assign a lambda expression, use a def"
break
if before.startswith('def '):
yield 0, "E704 multiple statements on one line (def)"
diff --git a/testsuite/E73.py b/testsuite/E73.py
index aab8a24..60fcd23 100644
--- a/testsuite/E73.py
+++ b/testsuite/E73.py
@@ -8,11 +8,11 @@ while False:
#: Okay
f = object()
f.method = lambda: 'Method'
-#: Okay
+
f = {}
f['a'] = lambda x: x ** 2
-#: Okay
+
f = []
f.append(lambda x: x ** 2)
-#: Okay
+
lambda: 'no-op'