Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer splitting right hand side of assignment statements. (#3368)
- Loading branch information
Showing
6 changed files
with
236 additions
and
18 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
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,85 @@ | ||
first_item, second_item = ( | ||
some_looooooooong_module.some_looooooooooooooong_function_name( | ||
first_argument, second_argument, third_argument | ||
) | ||
) | ||
|
||
some_dict["with_a_long_key"] = ( | ||
some_looooooooong_module.some_looooooooooooooong_function_name( | ||
first_argument, second_argument, third_argument | ||
) | ||
) | ||
|
||
# Make sure it works when the RHS only has one pair of (optional) parens. | ||
first_item, second_item = ( | ||
some_looooooooong_module.SomeClass.some_looooooooooooooong_variable_name | ||
) | ||
|
||
some_dict["with_a_long_key"] = ( | ||
some_looooooooong_module.SomeClass.some_looooooooooooooong_variable_name | ||
) | ||
|
||
# Make sure chaining assignments work. | ||
first_item, second_item, third_item, forth_item = m["everything"] = ( | ||
some_looooooooong_module.some_looooooooooooooong_function_name( | ||
first_argument, second_argument, third_argument | ||
) | ||
) | ||
|
||
# Make sure when the RHS's first split at the non-optional paren fits, | ||
# we split there instead of the outer RHS optional paren. | ||
first_item, second_item = some_looooooooong_module.some_loooooog_function_name( | ||
first_argument, second_argument, third_argument | ||
) | ||
|
||
( | ||
first_item, | ||
second_item, | ||
third_item, | ||
forth_item, | ||
fifth_item, | ||
last_item_very_loooooong, | ||
) = some_looooooooong_module.some_looooooooooooooong_function_name( | ||
first_argument, second_argument, third_argument | ||
) | ||
|
||
( | ||
first_item, | ||
second_item, | ||
third_item, | ||
forth_item, | ||
fifth_item, | ||
last_item_very_loooooong, | ||
) = everyting = some_loooooog_function_name( | ||
first_argument, second_argument, third_argument | ||
) | ||
|
||
|
||
# Make sure unsplittable type ignore won't be moved. | ||
some_kind_of_table[some_key] = util.some_function( # type: ignore # noqa: E501 | ||
some_arg | ||
).intersection(pk_cols) | ||
|
||
some_kind_of_table[ | ||
some_key | ||
] = lambda obj: obj.some_long_named_method() # type: ignore # noqa: E501 | ||
|
||
some_kind_of_table[ | ||
some_key # type: ignore # noqa: E501 | ||
] = lambda obj: obj.some_long_named_method() | ||
|
||
|
||
# Make when when the left side of assignement plus the opening paren "... = (" is | ||
# exactly line length limit + 1, it won't be split like that. | ||
xxxxxxxxx_yyy_zzzzzzzz[ | ||
xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1) | ||
] = 1 | ||
|
||
|
||
# Right side of assignment contains un-nested pairs of inner parens. | ||
some_kind_of_instance.some_kind_of_map[a_key] = ( | ||
isinstance(some_var, SomeClass) | ||
and table.something_and_something != table.something_else | ||
) or ( | ||
isinstance(some_other_var, BaseClass) and table.something != table.some_other_thing | ||
) |
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,38 @@ | ||
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source. | ||
|
||
# Left hand side fits in a single line but will still be exploded by the | ||
# magic trailing comma. | ||
first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv( | ||
arg1, | ||
arg2, | ||
) | ||
|
||
# Make when when the left side of assignement plus the opening paren "... = (" is | ||
# exactly line length limit + 1, it won't be split like that. | ||
xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1 | ||
|
||
|
||
# output | ||
|
||
|
||
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source. | ||
|
||
# Left hand side fits in a single line but will still be exploded by the | ||
# magic trailing comma. | ||
( | ||
first_value, | ||
( | ||
m1, | ||
m2, | ||
), | ||
third_value, | ||
) = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv( | ||
arg1, | ||
arg2, | ||
) | ||
|
||
# Make when when the left side of assignement plus the opening paren "... = (" is | ||
# exactly line length limit + 1, it won't be split like that. | ||
xxxxxxxxx_yyy_zzzzzzzz[ | ||
xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1) | ||
] = 1 |