Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up _is_eol_token #1257

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +1838 to +1841
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about this IndexErroring -- though the only case I can think of is DEDENT tokens on a blank line triggering this? and I'd expect the testsuite to catch that already

I know we had trouble with ENDMARKER in the past -- there are several patch versions where python reports end-of-file inconsistently / incorrectly -- especially when it either doesn't end with a newline or ends with an escape sequence (and unfortunately I think our test coverage is lacking here!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review :). I wasn't able to trigger an IndexError with this patch, but I may be overlooking some test cases.

I left some testing notes below in case someone else picks this up in the future.


Testing notes

Test cases:

Release versions tested:

  • 3.8.0 - 3.8.19
  • 3.9.0 - 3.9.19 (3.9.3 was yanked)
  • 3.10.0 - 3.10.14
  • 3.11.0 - 3.11.9
  • 3.12.0 - 3.12.3


return token[4][token[3][1]:].lstrip() == '\\\n'


########################################################################
Expand Down
Loading