-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Remove redundant parentheses around awaited coroutines/tasks #2991
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
Merged
+210
−1
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a2de75
await brackets
jpy-git a11a49a
Update CHANGES.md
jpy-git 6ec5627
Extra unit tests and nested await
jpy-git 09da677
Use recursion to remove redundant brackets from nested awaits
jpy-git 99bd47a
Merge branch 'main' into async_brackets
JelleZijlstra d170922
Extra unit tests
jpy-git be299bb
Merge branch 'main' into async_brackets
jpy-git ee470d6
Merge branch 'main' into async_brackets
ichard26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import asyncio | ||
|
|
||
| # Control example | ||
| async def main(): | ||
| await asyncio.sleep(1) | ||
|
|
||
| # Remove brackets for short coroutine/task | ||
| async def main(): | ||
| await (asyncio.sleep(1)) | ||
|
|
||
| async def main(): | ||
| await ( | ||
| asyncio.sleep(1) | ||
| ) | ||
|
|
||
| async def main(): | ||
| await (asyncio.sleep(1) | ||
| ) | ||
|
|
||
| # Check comments | ||
| async def main(): | ||
| await ( # Hello | ||
| asyncio.sleep(1) | ||
| ) | ||
|
|
||
| async def main(): | ||
| await ( | ||
| asyncio.sleep(1) # Hello | ||
| ) | ||
|
|
||
| async def main(): | ||
| await ( | ||
| asyncio.sleep(1) | ||
| ) # Hello | ||
|
|
||
| # Long lines | ||
| async def main(): | ||
| await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1)) | ||
|
|
||
| # Same as above but with magic trailing comma in function | ||
| async def main(): | ||
| await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1),) | ||
|
|
||
| # Cr@zY Br@ck3Tz | ||
| async def main(): | ||
| await ( | ||
| ((((((((((((( | ||
| ((( ((( | ||
| ((( ((( | ||
| ((( ((( | ||
| ((( ((( | ||
| ((black(1))) | ||
| ))) ))) | ||
| ))) ))) | ||
| ))) ))) | ||
| ))) ))) | ||
| ))))))))))))) | ||
| ) | ||
|
|
||
| # Keep brackets around non power operations and nested awaits | ||
| async def main(): | ||
| await (set_of_tasks | other_set) | ||
|
|
||
| async def main(): | ||
| await (await asyncio.sleep(1)) | ||
|
|
||
| # It's awaits all the way down... | ||
| async def main(): | ||
| await (await x) | ||
|
|
||
| async def main(): | ||
| await (yield x) | ||
|
|
||
| async def main(): | ||
| await (await (asyncio.sleep(1))) | ||
|
|
||
| async def main(): | ||
| await (await (await (await (await (asyncio.sleep(1)))))) | ||
|
jpy-git marked this conversation as resolved.
|
||
|
|
||
| # output | ||
| import asyncio | ||
|
|
||
| # Control example | ||
| async def main(): | ||
| await asyncio.sleep(1) | ||
|
|
||
|
|
||
| # Remove brackets for short coroutine/task | ||
| async def main(): | ||
| await asyncio.sleep(1) | ||
|
|
||
|
|
||
| async def main(): | ||
| await asyncio.sleep(1) | ||
|
|
||
|
|
||
| async def main(): | ||
| await asyncio.sleep(1) | ||
|
|
||
|
|
||
| # Check comments | ||
| async def main(): | ||
| await asyncio.sleep(1) # Hello | ||
|
|
||
|
|
||
| async def main(): | ||
| await asyncio.sleep(1) # Hello | ||
|
|
||
|
|
||
| async def main(): | ||
| await asyncio.sleep(1) # Hello | ||
|
|
||
|
|
||
| # Long lines | ||
| async def main(): | ||
| await asyncio.gather( | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| ) | ||
|
|
||
|
|
||
| # Same as above but with magic trailing comma in function | ||
| async def main(): | ||
| await asyncio.gather( | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| asyncio.sleep(1), | ||
| ) | ||
|
|
||
|
|
||
| # Cr@zY Br@ck3Tz | ||
| async def main(): | ||
| await black(1) | ||
|
|
||
|
|
||
| # Keep brackets around non power operations and nested awaits | ||
| async def main(): | ||
| await (set_of_tasks | other_set) | ||
|
|
||
|
|
||
| async def main(): | ||
| await (await asyncio.sleep(1)) | ||
|
|
||
|
|
||
| # It's awaits all the way down... | ||
| async def main(): | ||
| await (await x) | ||
|
|
||
|
|
||
| async def main(): | ||
| await (yield x) | ||
|
|
||
|
|
||
| async def main(): | ||
| await (await asyncio.sleep(1)) | ||
|
|
||
|
|
||
| async def main(): | ||
| await (await (await (await (await asyncio.sleep(1))))) | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.