From 187c8d52df22acb98508563b660fdf039c250a91 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 10 Jul 2023 13:18:50 +0200 Subject: [PATCH] Add some documentation --- crates/ruff_python_formatter/src/expression/parentheses.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ruff_python_formatter/src/expression/parentheses.rs b/crates/ruff_python_formatter/src/expression/parentheses.rs index a3087eebe43cd..670293e744eb6 100644 --- a/crates/ruff_python_formatter/src/expression/parentheses.rs +++ b/crates/ruff_python_formatter/src/expression/parentheses.rs @@ -124,6 +124,9 @@ pub(crate) fn is_expression_parenthesized(expr: AnyNodeRef, contents: &str) -> b ) } +/// Formats `content` enclosed by the `left` and `right` parentheses. The implementation also ensures +/// that expanding the parenthesized expression (or any of its children) doesn't enforce the +/// optional parentheses around the outer-most expression to materialize. pub(crate) fn parenthesized<'content, 'ast, Content>( left: &'static str, content: &'content Content, @@ -175,6 +178,8 @@ impl<'ast> Format> for FormatParenthesized<'_, 'ast> { } } +/// Makes `content` a group, but only if the outer expression is parenthesized (a list, parenthesized expression, dict, ...) +/// or if the expression gets parenthesized because it expands over multiple lines. pub(crate) fn in_parentheses_only_group<'content, 'ast, Content>( content: &'content Content, ) -> FormatInParenthesesOnlyGroup<'content, 'ast>