Replace verbatim text with NOT_YET_IMPLEMENTED#4904
Merged
MichaReiser merged 1 commit intomainfrom Jun 7, 2023
Merged
Conversation
Member
Author
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
MichaReiser
commented
Jun 6, 2023
| x = 0O777 .real | ||
| x = 0.000000006 .hex() | ||
| x = -100.0000J | ||
| NOT_YET_IMPLEMENTED_StmtAssign |
Member
Author
There was a problem hiding this comment.
An added benefit of this change is that it is easier to spot what formatting is implemented and what is incorrectly formatted because it is not yet supported.
a7c1782 to
a55ccd8
Compare
This was referenced Jun 6, 2023
MichaReiser
commented
Jun 6, 2023
|
|
||
|
|
||
| three_leading_newlines = 80 | ||
| NOT_YET_IMPLEMENTED_StmtAssign |
Member
Author
There was a problem hiding this comment.
I agree, this is stupid... but it is how it is.
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
b2ec055 to
f23ff61
Compare
a55ccd8 to
59c3e35
Compare
This was referenced Jun 7, 2023
konstin
approved these changes
Jun 7, 2023
Member
Author
|
@MichaReiser started a stack merge that includes this pull request via Graphite. |
Member
Author
|
Graphite rebased this pull request as part of a merge. |
59c3e35 to
48ce57f
Compare
Member
Author
|
@MichaReiser merged this pull request with Graphite. |
konstin
pushed a commit
that referenced
this pull request
Jun 13, 2023
<!--
Thank you for contributing to Ruff! To help us out with reviewing, please consider the following:
- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->
## Summary
This PR replaces the `verbatim_text` builder with a `not_yet_implemented` builder that emits `NOT_YET_IMPLEMENTED_<NodeKind>` for not yet implemented nodes.
The motivation for this change is that partially formatting compound statements can result in incorrectly indented code, which is a syntax error:
```python
def func_no_args():
a; b; c
if True: raise RuntimeError
if False: ...
for i in range(10):
print(i)
continue
```
Get's reformatted to
```python
def func_no_args():
a; b; c
if True: raise RuntimeError
if False: ...
for i in range(10):
print(i)
continue
```
because our formatter does not yet support `for` statements and just inserts the text from the source.
## Downsides
Using an identifier will not work in all situations. For example, an identifier is invalid in an `Arguments ` position. That's why I kept `verbatim_text` around and e.g. use it in the `Arguments` formatting logic where incorrect indentations are impossible (to my knowledge). Meaning, `verbatim_text` we can opt in to `verbatim_text` when we want to iterate quickly on nodes that we don't want to provide a full implementation yet and using an identifier would be invalid.
## Upsides
Running this on main discovered stability issues with the newline handling that were previously "hidden" because of the verbatim formatting. I guess that's an upside :)
## Test Plan
None?
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
This PR replaces the
verbatim_textbuilder with anot_yet_implementedbuilder that emitsNOT_YET_IMPLEMENTED_<NodeKind>for not yet implemented nodes.The motivation for this change is that partially formatting compound statements can result in incorrectly indented code, which is a syntax error:
Get's reformatted to
because our formatter does not yet support
forstatements and just inserts the text from the source.Downsides
Using an identifier will not work in all situations. For example, an identifier is invalid in an
Argumentsposition. That's why I keptverbatim_textaround and e.g. use it in theArgumentsformatting logic where incorrect indentations are impossible (to my knowledge). Meaning,verbatim_textwe can opt in toverbatim_textwhen we want to iterate quickly on nodes that we don't want to provide a full implementation yet and using an identifier would be invalid.Upsides
Running this on main discovered stability issues with the newline handling that were previously "hidden" because of the verbatim formatting. I guess that's an upside :)
Test Plan
None?