From ec81dec43bd2a2958b7acf45fdbb483b25b53ab5 Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Fri, 9 Aug 2024 21:02:27 -0400 Subject: [PATCH] Speed up _is_eol_token --- pycodestyle.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pycodestyle.py b/pycodestyle.py index 6425596e..1783ded7 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1829,7 +1829,18 @@ def update_counts(s, counts): def _is_eol_token(token): - return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == '\\\n' + if token[0] in NEWLINE: + return True + + if token[0] == tokenize.ENDMARKER: + return False + + # Check if the line's penultimate character is a continuation + # character + if token[4][-2] != '\\': + return False + + return token[4][token[3][1]:].lstrip() == '\\\n' ########################################################################