-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the handling of
# fmt: skip
when it's at a colon line (#3148)
When the Leaf node with `# fmt: skip` is a NEWLINE inside a `suite` Node, the nodes to ignore should be from the siblings of the parent `suite` Node. There is a also a special case for the ASYNC token, where it expands to the grandparent Node where the ASYNC token is. This fixes GH-2646, GH-3126, GH-2680, GH-2421, GH-2339, and GH-2138.
- Loading branch information
Showing
4 changed files
with
120 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Make sure a leading comment is not removed. | ||
def some_func( unformatted, args ): # fmt: skip | ||
print("I am some_func") | ||
return 0 | ||
# Make sure this comment is not removed. | ||
|
||
|
||
# Make sure a leading comment is not removed. | ||
async def some_async_func( unformatted, args): # fmt: skip | ||
print("I am some_async_func") | ||
await asyncio.sleep(1) | ||
|
||
|
||
# Make sure a leading comment is not removed. | ||
class SomeClass( Unformatted, SuperClasses ): # fmt: skip | ||
def some_method( self, unformatted, args ): # fmt: skip | ||
print("I am some_method") | ||
return 0 | ||
|
||
async def some_async_method( self, unformatted, args ): # fmt: skip | ||
print("I am some_async_method") | ||
await asyncio.sleep(1) | ||
|
||
|
||
# Make sure a leading comment is not removed. | ||
if unformatted_call( args ): # fmt: skip | ||
print("First branch") | ||
# Make sure this is not removed. | ||
elif another_unformatted_call( args ): # fmt: skip | ||
print("Second branch") | ||
else : # fmt: skip | ||
print("Last branch") | ||
|
||
|
||
while some_condition( unformatted, args ): # fmt: skip | ||
print("Do something") | ||
|
||
|
||
for i in some_iter( unformatted, args ): # fmt: skip | ||
print("Do something") | ||
|
||
|
||
async def test_async_for(): | ||
async for i in some_async_iter( unformatted, args ): # fmt: skip | ||
print("Do something") | ||
|
||
|
||
try : # fmt: skip | ||
some_call() | ||
except UnformattedError as ex: # fmt: skip | ||
handle_exception() | ||
finally : # fmt: skip | ||
finally_call() | ||
|
||
|
||
with give_me_context( unformatted, args ): # fmt: skip | ||
print("Do something") | ||
|
||
|
||
async def test_async_with(): | ||
async with give_me_async_context( unformatted, args ): # fmt: skip | ||
print("Do something") |