Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange inconsistent behaviour #1208

Open
duburcqa opened this issue Mar 11, 2024 · 3 comments
Open

Strange inconsistent behaviour #1208

duburcqa opened this issue Mar 11, 2024 · 3 comments

Comments

@duburcqa
Copy link

duburcqa commented Mar 11, 2024

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,

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,

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
@duburcqa
Copy link
Author

duburcqa commented Mar 11, 2024

Strangely enough, it partially works if I commet out column_limit = 79, but I need to set the limit to 92 to avoid splitting the arguments of the function call inside the try catch... This limit is completely unrelated to the length of the line.

It seems to be related to #836

@kaddkaka
Copy link

Just trying to understand, what formatted result did you expect?

@duburcqa
Copy link
Author

duburcqa commented Mar 13, 2024

At least something consistent, but ideally:

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants