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

Conversation

correctmost
Copy link
Contributor

Continuation of #1256 because I force pushed and cannot reopen that PR. (Sorry for the noise.)

If this PR seems too risky because of assumptions about tokenization, feel free to pass!

Stats

Before

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1478156    0.885    0.000    1.197    0.000 pycodestyle.py:1831(_is_eol_token)
  1472360    0.364    0.000    0.364    0.000 {method 'lstrip' of 'str' objects}
Command Mean [s] Min [s] Max [s] Relative
pycodestyle . 18.472 ± 0.196 18.067 18.848 1.00

After

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1478156    0.511    0.000    0.511    0.000 pycodestyle.py:1831(_is_eol_token)
   225341    0.055    0.000    0.055    0.000 {method 'lstrip' of 'str' objects}
Command Mean [s] Min [s] Max [s] Relative
pycodestyle . 18.360 ± 0.186 18.159 18.781 1.00

@correctmost
Copy link
Contributor Author

Versions tested locally (on Arch Linux with pyenv):

  • 3.13.0b4
  • 3.12.4
  • 3.12.0
  • 3.11.9
  • 3.11.0
  • 3.10.14
  • 3.10.0
  • 3.9.19
  • 3.9.0
  • 3.8.19
  • 3.8.0

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

this one seems more risky than the others so I'm leaning towards passing on it

Comment on lines +1838 to +1841
# Check if the line's penultimate character is a continuation
# character
if token[4][-2] != '\\':
return False
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants