Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _format_foldable(
expression: Node, expression_context: ExpressionContext, context: Context
) -> Outcome:
if is_expression_forcing_multiple_lines(expression):
return _format_foldable_to_multiple_lines(
expression, expression_context, context
)
single_line_expression = expression_to_str(expression)
single_line_length = (
context.indent
+ len(expression_context.prefix_string)
+ len(single_line_expression)
+ len(expression_context.suffix_string)
)
if single_line_length <= context.max_line_length:
single_line = "{}{}{}{}".format(
context.indent_string,
expression_context.prefix_string,
expression_to_str(expression),
expression_context.suffix_string,
def format_comma_separated_list(
a_list: List[Node], expression_context: ExpressionContext, context: Context
) -> FormattedLines:
elements = [node for node in a_list if not is_any_comma(node)]
child_context = context.create_child_context(expression_context.prefix_line)
fake_expression = Tree("fake", a_list)
multiline_mode_forced = is_expression_forcing_multiple_lines(fake_expression)
if not multiline_mode_forced:
strings_to_join = list(map(standalone_expression_to_str, elements))
single_line_expression = "{}{}{}".format(
expression_context.prefix_string,
", ".join(strings_to_join),
expression_context.suffix_string,
)
single_line_length = len(single_line_expression) + context.indent
if single_line_length <= context.max_line_length:
return [
(
expression_context.prefix_line,
"{}{}".format(context.indent_string, single_line_expression),
)
]
indented_single_line_expression = ", ".join(strings_to_join)