google / google/yapf

How to avoid line break before comparison operator?

Open
#1,166 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Hi, I'm trying to adopt YAPF for a larger code base and am running into a few edge cases. Is there a configuration option to achieve the following desired output? Thanks!

Actual:

```python
long_variable_name = (long_variable_name
== long_variable_name) and (long_variable_name == 1)
```

Desired:

```python
long_variable_name = (
(long_variable_name == long_variable_name) and (long_variable_name == 1))

# OR

long_variable_name = (
(long_variable_name == long_variable_name) and
(long_variable_name == 1))

# OR at least

long_variable_name = (
long_variable_name == long_variable_name) and (long_variable_name == 1))
```

pyproject.toml

```toml
[tool.yapf]
based_on_style = "pep8"
indent_width = 2
allow_multiline_lambdas = true
continuation_align_style = "FIXED"
continuation_indent_width = 4
dedent_closing_brackets = false
each_dict_entry_on_separate_line = false
spaces_around_power_operator = true
split_arguments_when_comma_terminated = true
split_before_closing_bracket = false
split_before_expression_after_opening_paren = true
split_before_first_argument = true
split_before_logical_operator = false
split_before_named_assigns = false
split_complex_comprehension = true
```

Maybe what's missing here is something like `split_before_first_argument = true` but for parens that group code statements rather than just argument lists of function calls?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.