Extra indent space in tuple

564 Views Asked by At

I have the following line of python (2.7) code.

audit_row_groups = [(key, list(group), ) for key, group in itertools.groupby(audit_rows, lambda row: (row['date'], row['table_name'], row['user_id']))]

When yapf formats it, I get the following:

audit_row_groups = [
    (key, list(group),
     ) for key, group in itertools.groupby(
         audit_rows, lambda row: (row['date'], row['table_name'], row['user_id']))]

The 3rd line is indented with 5 spaces instead of 4. The last line is indented with 9 spaces instead of 8. My pylint check then complains there is 1 too many spaces on the 3rd line.

I'm using yapf 0.30.0 with the following style:

[style]
align_closing_bracket_with_visual_indent=True
allow_multiline_dictionary_keys=True
allow_multiline_lambdas=True
allow_split_before_default_or_named_assigns=False
allow_split_before_dict_value=True
arithmetic_precedence_indication=False
blank_lines_around_top_level_definition=1
blank_line_before_class_docstring=False
blank_line_before_module_docstring=False
blank_line_before_nested_class_or_def=False
coalesce_brackets=False
column_limit=100
continuation_align_style=SPACE
continuation_indent_width=4
dedent_closing_brackets=False
disable_ending_comma_heuristic=True
each_dict_entry_on_separate_line=False
force_multiline_dict=False
i18n_comment=
i18n_function_call=
indent_blank_lines=False
indent_closing_brackets=False
indent_dictionary_value=False
indent_width=4
join_multiple_lines=True
no_spaces_around_selected_binary_operators=
spaces_around_default_or_named_assign=False
spaces_around_dict_delimiters=False
spaces_around_list_delimiters=False
spaces_around_power_operator=False
spaces_around_subscript_colon=False
spaces_around_tuple_delimiters=False
spaces_before_comment=1
space_between_ending_comma_and_closing_bracket=False
space_inside_brackets=False
split_all_comma_separated_values=False
split_all_top_level_comma_separated_values=False
split_arguments_when_comma_terminated=False
split_before_arithmetic_operator=False
split_before_bitwise_operator=False
split_before_closing_bracket=False
split_before_dict_set_generator=False
split_before_dot=False
split_before_expression_after_opening_paren=False
split_before_first_argument=False
split_before_logical_operator=True
split_before_named_assigns=False
split_complex_comprehension=True
split_penalty_after_opening_bracket=300
split_penalty_after_unary_operator=10000
split_penalty_arithmetic_operator=300
split_penalty_before_if_expr=0
split_penalty_bitwise_operator=300
split_penalty_comprehension=80
split_penalty_excess_character=7000
split_penalty_for_added_line_split=9000
split_penalty_import_names=0
split_penalty_logical_operator=300
use_tabs=False

I've already tried to change the space_between_ending_comma_and_closing_bracket to False/True. If I remove the trailing comma in the tuple on line 2, then it works as expected, but this goes against the recommendation of using a trailing comma in a tuple.

Any idea how I can improve this setup to remove this extra space?

Thanks, Grant

1

There are 1 best solutions below

0
On

I just ran into the exact same problem today and was able to solve it. The very first argument in your config file is the cause of this extra whitespace :D

You need:

[style]
align_closing_bracket_with_visual_indent=False

Then you will get the expected result:

audit_row_groups = [
    (key, list(group),
    ) for key, group in itertools.groupby(
        audit_rows, lambda row: (row['date'], row['table_name'], row['user_id']))]

Even if your issue was so long ago, I just wanted to answer it briefly. Maybe someone else will run into this problem :)

Best regards, Philipp