summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lee <IanLee1521@gmail.com>2016-06-02 14:41:20 -0700
committerIan Lee <IanLee1521@gmail.com>2016-06-02 14:41:20 -0700
commitb02d7687ee4de8f501195644bc9dc7fac523e52e (patch)
tree2180c2e6d1c77beb5524550ecfa279b292a35a4d
parent3944d9e2e8de97e65fa297a61f245ce0eae9e6d9 (diff)
parent594908607f98225884515bf225fb5e7a735e6722 (diff)
downloadpep8-b02d7687ee4de8f501195644bc9dc7fac523e52e.tar.gz
Merge pull request #522 from arthall/issue-314
Updated pull request #314 to current master.
-rwxr-xr-xpycodestyle.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 7026396..e52cfbd 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -958,22 +958,25 @@ def compound_statements(logical_line):
line = logical_line
last_char = len(line) - 1
found = line.find(':')
+ prev_found = 0
+ counts = dict((char, 0) for char in '{}[]()')
while -1 < found < last_char:
- before = line[:found]
- if ((before.count('{') <= before.count('}') and # {'a': 1} (dict)
- before.count('[') <= before.count(']') and # [1:2] (slice)
- before.count('(') <= before.count(')'))): # (annotation)
- lambda_kw = LAMBDA_REGEX.search(before)
+ update_counts(line[prev_found:found], counts)
+ if ((counts['{'] <= counts['}'] and # {'a': 1} (dict)
+ counts['['] <= counts[']'] and # [1:2] (slice)
+ counts['('] <= counts[')'])): # (annotation)
+ lambda_kw = LAMBDA_REGEX.search(line, 0, found)
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 '):
+ if line.startswith('def '):
yield 0, "E704 multiple statements on one line (def)"
else:
yield found, "E701 multiple statements on one line (colon)"
+ prev_found = found
found = line.find(':', found + 1)
found = line.find(';')
while -1 < found:
@@ -1333,8 +1336,18 @@ def filename_match(filename, patterns, default=True):
return any(fnmatch(filename, pattern) for pattern in patterns)
+def update_counts(s, counts):
+ r"""Adds one to the counts of each appearence of characters in s,
+ for characters in counts"""
+ for char in s:
+ if char in counts:
+ counts[char] += 1
+
+
def _is_eol_token(token):
return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == '\\\n'
+
+
if COMMENT_WITH_NL:
def _is_eol_token(token, _eol_token=_is_eol_token):
return _eol_token(token) or (token[0] == tokenize.COMMENT and