Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
and statement.children[1].data == "parent_call"
else None
)
parent_call = (
statement.children[2]
if len(statement.children) > 2
and isinstance(statement.children[2], Tree)
and statement.children[2].data == "parent_call"
else parent_call
)
if parent_call is not None:
last_line_no, last_line = formatted_lines[-1]
expression_context = ExpressionContext(
"{}.(".format(last_line.strip()), last_line_no, ")" # type: ignore
)
elements = [e for e in parent_call.children[1:-1] if not is_any_comma(e)]
formatted_lines = formatted_lines[:-1] + format_comma_separated_list(
elements, expression_context, context
)
return_type = (
statement.children[1]
if isinstance(statement.children[1], Token)
and statement.children[1].type == "TYPE"
else None
)
return_type = (
statement.children[2]
if len(statement.children) > 2
and isinstance(statement.children[2], Token)
and statement.children[2].type == "TYPE"
else return_type
)
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),
def _format_setget_and_append_to_outcome(setget: Tree, outcome: Outcome) -> Outcome:
setget_string = (
" setget {}, {}".format(setget.children[1].value, setget.children[3].value)
if len(setget.children) > 2 and is_any_comma(setget.children[2])
else (
" setget {}".format(setget.children[1])
if len(setget.children) == 2
else " setget , {}".format(setget.children[2].value)
)
)
formatted_lines, _ = outcome
last_line_no, last_line = formatted_lines[-1]
formatted_lines = formatted_lines[:-1] + [(last_line_no, last_line + setget_string)]
return (formatted_lines, setget.end_line)
def _array_to_str(array: Tree) -> str:
elements = [
standalone_expression_to_str(child)
for child in array.children
if not is_any_comma(child)
]
return "[{}]".format(", ".join(elements))
def _arguments_to_str(arguments: List[Node]) -> str:
return ", ".join(
[
standalone_expression_to_str(argument)
for argument in arguments
if not is_any_parentheses(argument) and not is_any_comma(argument)
]