Range formatting: Fix invalid syntax after parenthesizing expression (#9751)

This commit is contained in:
Micha Reiser 2024-02-02 17:56:25 +01:00 committed by GitHub
parent 50bfbcf568
commit 4f7fb566f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 351 additions and 212 deletions

View file

@ -0,0 +1 @@
a + b<RANGE_START><RANGE_END>

View file

@ -0,0 +1,13 @@
def needs_parentheses( ) -> bool:
return item.sizing_mode is None and <RANGE_START>item.width_policy == "auto" and item.height_policy == "automatic"<RANGE_END>
def no_longer_needs_parentheses( ) -> bool:
return (
<RANGE_START>item.width_policy == "auto"
and item.height_policy == "automatic"<RANGE_END>
)
def format_range_after_inserted_parens ():
a and item.sizing_mode is None and item.width_policy == "auto" and item.height_policy == "automatic"<RANGE_START>
print("Format this" ) <RANGE_END>

View file

@ -67,3 +67,19 @@ def convert_str(value: str) -> str: # Trailing comment
<RANGE_END>
def test ():
pass
def test_comment_indent():
<RANGE_START># A misaligned comment<RANGE_END>
print("test")
# This demonstrates the use case where a user inserts a new function or class after an existing function.
# In this case, we should avoid formatting the node that directly precedes the new function/class.
# However, the problem is that the preceding node **must** be formatted to determine the whitespace between the two statements.
def test_start ():
print("Ideally this gets not reformatted" )
<RANGE_START>
def new_function_inserted_after_test_start ():
print("This should get formatted" )<RANGE_END>