From f8620d0fa1a087b9696a47f8a1ba45e529bfdb93 Mon Sep 17 00:00:00 2001 From: Sam-Cleveland Date: Wed, 22 Jun 2022 07:24:38 -0700 Subject: [PATCH] Update for false negatives with E731 lambda assignments Changed out the current implementation of lambda assignment detection for a regex based one. --- pycodestyle.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pycodestyle.py b/pycodestyle.py index f866dd4a..db6d21ed 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -140,7 +140,9 @@ ) 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') +LAMBDA_ASSIGNMENT_REGEX = re.compile( + r'(?= (3, 8) and line[found + 1] == '=')): # assignment expression - lambda_kw = LAMBDA_REGEX.search(line, 0, found) - if lambda_kw: - before = line[:lambda_kw.start()].rstrip() - if before[-1:] == '=' and before[:-1].strip().isidentifier(): - yield 0, ("E731 do not assign a lambda expression, use a " - "def") - break if STARTSWITH_DEF_REGEX.match(line): yield 0, "E704 multiple statements on one line (def)" elif STARTSWITH_INDENT_STATEMENT_REGEX.match(line):