Strange inconsistent behaviour
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
I don't understand why two seemingly identical lines get formatted differently. The inconsistency is very surprising to me. Maybe there is some undocumented penalty hiding somewhere in the implementation. In particular,
```python
class Foo:
def bar(self) -> None:
if self.observer.state_space is not None:
state_spaces = observation_space.setdefault('states',
gym.spaces.Dict())
try:
self.env.register_variable( # type: ignore[attr-defined]
'state', state, None, self.observer.name)
except ValueError:
pass
feature_spaces = observation_space.setdefault('features',
gym.spaces.Dict())
```
is reformatted as,
```python
class Foo:
def bar(self) -> None:
if self.observer.state_space is not None:
state_spaces = observation_space.setdefault(
'states', gym.spaces.Dict())
try:
self.env.register_variable( # type: ignore[attr-defined]
'state',
state,
None,
self.observer.name)
except ValueError:
pass
feature_spaces = observation_space.setdefault('features',
gym.spaces.Dict())
```
Here are the options I'm using:
```
align_closing_bracket_with_visual_indent = True
allow_multiline_lambdas = False
allow_multiline_dictionary_keys = False
allow_split_before_dict_value = False
allow_split_before_default_or_named_assigns = False
arithmetic_precedence_indication = False
blank_lines_around_top_level_definition = 2
blank_line_before_module_docstring = False
blank_line_before_class_docstring = False
blank_line_before_nested_class_or_def = True
coalesce_brackets = True
column_limit = 79
continuation_align_style = SPACE
blank_lines_between_top_level_imports_and_variables = 2
dedent_closing_brackets = False
disable_ending_comma_heuristic = True
#disable_split_list_with_comment = False
each_dict_entry_on_separate_line = True
indent_dictionary_value = True
indent_width = 4
indent_blank_lines = False
indent_closing_brackets = False
join_multiple_lines = True
no_spaces_around_selected_binary_operators = True
space_between_ending_comma_and_closing_bracket = False
space_inside_brackets = False
spaces_around_dict_delimiters = False
spaces_around_list_delimiters = False
spaces_around_power_operator = True
spaces_around_subscript_colon = False
spaces_around_tuple_delimiters = False
spaces_before_comment = 2
split_all_comma_separated_values = False
split_all_top_level_comma_separated_values = True
split_arguments_when_comma_terminated = True
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 = True
split_before_first_argument = False
split_before_logical_operator = False
split_before_named_assigns = True
split_complex_comprehension = False
split_penalty_after_opening_bracket = 50
split_penalty_arithmetic_operator = 600
split_penalty_before_if_expr = 100
split_penalty_comprehension = 200
split_penalty_for_added_line_split = 950
use_tabs = False
```
Contributor guide
Assessment
This issue has not been assessed yet.