-
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.
Better manage return annotation brackets (#2990)
Allows us to better control placement of return annotations by: a) removing redundant parens b) moves very long type annotations onto their own line Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
- Loading branch information
1 parent
f6188ce
commit 98fccce
Showing
5 changed files
with
255 additions
and
1 deletion.
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,222 @@ | ||
# Control | ||
def double(a: int) -> int: | ||
return 2*a | ||
|
||
# Remove the brackets | ||
def double(a: int) -> (int): | ||
return 2*a | ||
|
||
# Some newline variations | ||
def double(a: int) -> ( | ||
int): | ||
return 2*a | ||
|
||
def double(a: int) -> (int | ||
): | ||
return 2*a | ||
|
||
def double(a: int) -> ( | ||
int | ||
): | ||
return 2*a | ||
|
||
# Don't lose the comments | ||
def double(a: int) -> ( # Hello | ||
int | ||
): | ||
return 2*a | ||
|
||
def double(a: int) -> ( | ||
int # Hello | ||
): | ||
return 2*a | ||
|
||
# Really long annotations | ||
def foo() -> ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
): | ||
return 2 | ||
|
||
def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: | ||
return 2 | ||
|
||
def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: | ||
return 2 | ||
|
||
def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: | ||
return 2 | ||
|
||
def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: | ||
return 2 | ||
|
||
# Split args but no need to split return | ||
def foo(a: int, b: int, c: int,) -> int: | ||
return 2 | ||
|
||
# Deeply nested brackets | ||
# with *interesting* spacing | ||
def double(a: int) -> (((((int))))): | ||
return 2*a | ||
|
||
def double(a: int) -> ( | ||
( ( | ||
((int) | ||
) | ||
) | ||
) | ||
): | ||
return 2*a | ||
|
||
def foo() -> ( | ||
( ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
) | ||
)): | ||
return 2 | ||
|
||
# Return type with commas | ||
def foo() -> ( | ||
tuple[int, int, int] | ||
): | ||
return 2 | ||
|
||
def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]: | ||
return 2 | ||
|
||
# Magic trailing comma example | ||
def foo() -> tuple[int, int, int,]: | ||
return 2 | ||
|
||
# Long string example | ||
def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnreasonablyExtremelyLongClassName]": | ||
pass | ||
|
||
# output | ||
# Control | ||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
# Remove the brackets | ||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
# Some newline variations | ||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
# Don't lose the comments | ||
def double(a: int) -> int: # Hello | ||
return 2 * a | ||
|
||
|
||
def double(a: int) -> int: # Hello | ||
return 2 * a | ||
|
||
|
||
# Really long annotations | ||
def foo() -> ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
): | ||
return 2 | ||
|
||
|
||
def foo() -> ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
): | ||
return 2 | ||
|
||
|
||
def foo() -> ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
): | ||
return 2 | ||
|
||
|
||
def foo( | ||
a: int, | ||
b: int, | ||
c: int, | ||
) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: | ||
return 2 | ||
|
||
|
||
def foo( | ||
a: int, | ||
b: int, | ||
c: int, | ||
) -> ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
): | ||
return 2 | ||
|
||
|
||
# Split args but no need to split return | ||
def foo( | ||
a: int, | ||
b: int, | ||
c: int, | ||
) -> int: | ||
return 2 | ||
|
||
|
||
# Deeply nested brackets | ||
# with *interesting* spacing | ||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
def double(a: int) -> int: | ||
return 2 * a | ||
|
||
|
||
def foo() -> ( | ||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | ||
): | ||
return 2 | ||
|
||
|
||
# Return type with commas | ||
def foo() -> tuple[int, int, int]: | ||
return 2 | ||
|
||
|
||
def foo() -> ( | ||
tuple[ | ||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, | ||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, | ||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, | ||
] | ||
): | ||
return 2 | ||
|
||
|
||
# Magic trailing comma example | ||
def foo() -> ( | ||
tuple[ | ||
int, | ||
int, | ||
int, | ||
] | ||
): | ||
return 2 | ||
|
||
|
||
# Long string example | ||
def frobnicate() -> ( | ||
"ThisIsTrulyUnreasonablyExtremelyLongClassName |" | ||
" list[ThisIsTrulyUnreasonablyExtremelyLongClassName]" | ||
): | ||
pass |
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