google / yapf

A formatter for Python files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set specific options for keywords

gzachariadis opened this issue · comments

I am trying to add split_all_comma_separated_values = true but only for the keyword import.

Namely, I want my imports to look like this

from x import (
    a,
    b,
    c,
    d,
)

without having to set split_all_comma_seperated_values to true for the entire document.

I know I can do

# yapf: disable

from x import (
    a,
    b,
    c,
    d,
)

# yapf: enable

but I am looking for an option that certain keywords like try or except will also feature a black line before them. Please advise on my options.

My current YAPF Configuration file for reference

# YAPF Configuration File

[style]
column_limit = 120
indent_width = 4
use_tabs = false
continuation_indent_width = 4
continuation_align_style = valign-right
join_multiple_lines = false
align_closing_bracket_with_visual_indent = false
allow_multiline_dictionary_keys = true
allow_multiline_lambdas = false
allow_split_before_default_or_named_assigns = true
allow_split_before_dict_value = true
arithmetic_precedence_indication = true
blank_line_before_class_docstring = true
blank_line_before_nested_class_or_def = true
blank_lines_around_top_level_definition = 1
blank_lines_between_top_level_imports_and_variables = 2
coalesce_brackets = true
dedent_closing_brackets = true
disable_ending_comma_heuristic = true
each_dict_entry_on_separate_line = true
force_multiline_dict = true
i18n_comment = "#! todo:"
i18n_function_call = []
indent_blank_lines = false
indent_closing_brackets = true
indent_dictionary_value = true
no_spaces_around_selected_binary_operators = ['/']
space_between_ending_comma_and_closing_bracket = false
space_inside_brackets = false
spaces_around_default_or_named_assign = true
spaces_around_dict_delimiters = true
spaces_around_list_delimiters = false
spaces_around_power_operator = false
spaces_around_subscript_colon = true
spaces_around_tuple_delimiters = false
spaces_before_comment="15, 20"
split_all_comma_separated_values = false
split_all_top_level_comma_separated_values = true
split_arguments_when_comma_terminated = false
split_before_arithmetic_operator = false
split_before_bitwise_operator = false
split_before_closing_bracket = true
split_before_dict_set_generator = true
split_before_dot = false
split_before_expression_after_opening_paren = false
split_before_first_argument = true
split_before_logical_operator = true
split_before_named_assigns = false
split_complex_comprehension = true
split_penalty_after_opening_bracket = 0
split_penalty_after_unary_operator = 100
split_penalty_arithmetic_operator = 0
split_penalty_before_if_expr = 100
split_penalty_bitwise_operator = 0
split_penalty_comprehension = 100
split_penalty_excess_character = 1
split_penalty_for_added_line_split = 50
split_penalty_import_names = 10
split_penalty_logical_operator = 100