Format target: annotation = value? expressions#5661
Conversation
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
95afea9 to
5689102
Compare
|
|
||
| /// Adds parentheses and indents `content` if it doesn't fit on a line. | ||
| pub(crate) fn optional_parentheses<'ast, T>(content: &T) -> OptionalParentheses<'_, 'ast> | ||
| pub(crate) fn parenthesize_if_expands<'ast, T>(content: &T) -> ParenthesizeIfExpands<'_, 'ast> |
There was a problem hiding this comment.
I think this name is better. The rest of the code refers to optional parentheses that we sometimes omit because they are unnecessary. These are parentheses that we always add if the content expands.
| // Add optional parentheses. Ignore if the item renders parentheses itself. | ||
| Parentheses::Optional => { | ||
| if can_omit_optional_parentheses(item, f.context()) { | ||
| let saved_level = f.context().node_level(); |
There was a problem hiding this comment.
I moved this, unchanged, to parentheses.rs
| return_annotation | ||
| .format() | ||
| .with_options(Parenthesize::IfBreaks) | ||
| optional_parentheses( |
There was a problem hiding this comment.
Function defs are weird. They add parentheses around subscript expressions.
| let options = PyFormatOptions::default(); | ||
| let options_path = input_path.with_extension("options.json"); | ||
|
|
||
| let options: PyFormatOptions = if let Ok(options_file) = fs::File::open(options_path) { |
There was a problem hiding this comment.
This adds support for options for black tests.
| + ... | ||
| + | ||
| + | ||
| +def spam() -> None: |
There was a problem hiding this comment.
Hmm, we'll need into single line bodies at some point. Potentially something that our suite refactor would simplify but we shouldn't be blocked by it.l
5689102 to
018b5d2
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
32813bd to
9cc7c21
Compare
018b5d2 to
a9c9dd5
Compare
9cc7c21 to
f3444d0
Compare
a9c9dd5 to
3fbd025
Compare
3fbd025 to
30e7756
Compare

Summary
This PR implements formatting of
target: annotation (= value)?expressions.It resulted in me going down a rabbit hole because I then noticed that tuples inside of subscript should not be parenthesized. So I fixed that too.
Test Plan
I added new tests. I fixed the
skip_magic_commatest to run it with magic comma disabled (This test got me really confused because one test wanted to have trailing comma and this test wanted not to have trailing commas).