Skip LibCST parsing for standard dedent adjustments#9769
Merged
charliermarsh merged 2 commits intomainfrom Feb 2, 2024
Merged
Conversation
a9bc579 to
74c9589
Compare
74c9589 to
dd0727e
Compare
CodSpeed Performance ReportMerging #9769 will improve performances by 29.71%Comparing Summary
Benchmarks breakdown
|
dd0727e to
3f9ae92
Compare
charliermarsh
commented
Feb 2, 2024
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| S101 | 117 | 0 | 117 | 0 | 0 |
| ANN202 | 70 | 0 | 70 | 0 | 0 |
| FA100 | 55 | 0 | 55 | 0 | 0 |
| AIR001 | 40 | 0 | 40 | 0 | 0 |
| ANN201 | 38 | 0 | 38 | 0 | 0 |
| ANN001 | 28 | 0 | 28 | 0 | 0 |
| D103 | 24 | 0 | 24 | 0 | 0 |
| T201 | 23 | 0 | 23 | 0 | 0 |
| PLC0415 | 18 | 0 | 18 | 0 | 0 |
| COM812 | 14 | 0 | 14 | 0 | 0 |
| SIM117 | 12 | 0 | 12 | 0 | 0 |
| FBT001 | 6 | 0 | 6 | 0 | 0 |
| FBT002 | 5 | 0 | 5 | 0 | 0 |
| PT012 | 5 | 0 | 5 | 0 | 0 |
| PTH118 | 5 | 0 | 5 | 0 | 0 |
| PTH123 | 4 | 0 | 4 | 0 | 0 |
| FIX002 | 4 | 0 | 4 | 0 | 0 |
| TD002 | 4 | 0 | 4 | 0 | 0 |
| TD003 | 4 | 0 | 4 | 0 | 0 |
| D106 | 4 | 0 | 4 | 0 | 0 |
| RET505 | 3 | 0 | 3 | 0 | 0 |
| D101 | 3 | 0 | 3 | 0 | 0 |
| D205 | 3 | 0 | 3 | 0 | 0 |
| ANN401 | 3 | 0 | 3 | 0 | 0 |
| B015 | 2 | 0 | 2 | 0 | 0 |
| CPY001 | 2 | 0 | 2 | 0 | 0 |
| D202 | 2 | 0 | 2 | 0 | 0 |
| D212 | 2 | 0 | 2 | 0 | 0 |
| PLW1514 | 2 | 0 | 2 | 0 | 0 |
| D107 | 2 | 0 | 2 | 0 | 0 |
| D400 | 2 | 0 | 2 | 0 | 0 |
| D415 | 2 | 0 | 2 | 0 | 0 |
| C408 | 2 | 0 | 2 | 0 | 0 |
| PERF401 | 1 | 0 | 1 | 0 | 0 |
| A002 | 1 | 0 | 1 | 0 | 0 |
| A001 | 1 | 0 | 1 | 0 | 0 |
| D100 | 1 | 0 | 1 | 0 | 0 |
| D401 | 1 | 0 | 1 | 0 | 0 |
| D404 | 1 | 0 | 1 | 0 | 0 |
| PTH100 | 1 | 0 | 1 | 0 | 0 |
| PTH120 | 1 | 0 | 1 | 0 | 0 |
| D209 | 1 | 0 | 1 | 0 | 0 |
| PLR0913 | 1 | 0 | 1 | 0 | 0 |
| PLR0917 | 1 | 0 | 1 | 0 | 0 |
| C901 | 1 | 0 | 1 | 0 | 0 |
| PLR0915 | 1 | 0 | 1 | 0 | 0 |
| PLR1702 | 1 | 0 | 1 | 0 | 0 |
| PLR6201 | 1 | 0 | 1 | 0 | 0 |
| PLR2004 | 1 | 0 | 1 | 0 | 0 |
| TD004 | 1 | 0 | 1 | 0 | 0 |
| RET504 | 1 | 0 | 1 | 0 | 0 |
| PLR0914 | 1 | 0 | 1 | 0 | 0 |
| ARG001 | 1 | 0 | 1 | 0 | 0 |
Formatter (stable)
ℹ️ ecosystem check encountered format errors. (no format changes; 2 project errors)
sphinx-doc/sphinx (error)
ruff format --no-preview --exclude tests/roots/test-pycode/cp_1251_coded.py
ruff failed
Cause: Selection of unstable rules without the `--preview` flag is not allowed. Enable preview or remove selection of:
- FURB113
- FURB131
- FURB132
openai/openai-cookbook (error)
warning: Detected debug build without --no-cache.
error: Failed to parse examples/dalle/Image_generations_edits_and_variations_with_DALL-E.ipynb:3:7:8: Unexpected token 'prompt'
Formatter (preview)
ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)
openai/openai-cookbook (error)
ruff format --preview
warning: Detected debug build without --no-cache.
error: Failed to parse examples/dalle/Image_generations_edits_and_variations_with_DALL-E.ipynb:3:7:8: Unexpected token 'prompt'
MichaReiser
approved these changes
Feb 2, 2024
Comment on lines
+141
to
+145
| // Look at the indentation of the first line, to determine the "baseline" indentation. | ||
| let existing_indent_len = text | ||
| .universal_newlines() | ||
| .next() | ||
| .map_or(0, |line| line.len() - line.trim_start().len()); |
Member
There was a problem hiding this comment.
Nit: Why not indentation_at_offset?
Member
Author
There was a problem hiding this comment.
Because the text here is the "full line", not the start of the content.
3f9ae92 to
43e972a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Often, when fixing, we need to dedent a block of code (e.g., if we remove an
ifand dedent its body). Today, we use LibCST to parse and adjust the indentation, which is really expensive -- but this is only really necessary if the block contains a multiline string, since naively adjusting the indentation for such a string can change the whitespace within the string.This PR uses a simple dedent implementation for cases in which the block doesn't intersect with a multi-line string (or an f-string, since we don't support tracking multi-line strings for f-strings right now).
We could improve this even further by using the ranges to guide the dedent function, such that we don't apply the dedent if the line starts within a multiline string. But that would also need to take f-strings into account, which is a little tricky.
Test Plan
cargo test