Skip to content

Commit e5a0579

Browse files
committed
Microoptimisation: avoid creating string slices
str.count() can limit the counting to a range of string positions.
1 parent cb8402a commit e5a0579

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pycodestyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ def python_3000_invalid_escape_sequence(logical_line, tokens):
15351535
while pos >= 0:
15361536
pos += 1
15371537
if string[pos] not in valid:
1538-
line = start_line + string[:pos].count('\n')
1538+
line = start_line + string.count('\n', 0, pos)
15391539
if line == start_line:
15401540
col = start_col + len(prefix) + len(quote) + pos
15411541
else:

0 commit comments

Comments
 (0)