---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/boolean_operation.py
---
## Input
```python
if (
    self._proc
    # has the child process finished?
    and self._returncode
    # the child process has finished, but the
    # transport hasn't been notified yet?
    and self._proc.poll()
):
    pass

if (
    self._proc
    and self._returncode
    and self._proc.poll()
    and self._proc
    and self._returncode
    and self._proc.poll()
):
    pass

if (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
):
    pass


if (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
    and aaaaaaaaaaaaaaaaa
):
    pass


if [2222, 333] and [
    aaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbb,
    cccccccccccccccccccc,
    dddddddddddddddddddd,
    eeeeeeeeee,
]:
    pass

if [
    aaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbb,
    cccccccccccccccccccc,
    dddddddddddddddddddd,
    eeeeeeeeee,
] and [2222, 333]:
    pass

# Break right only applies for boolean operations with a left and right side
if (
    aaaaaaaaaaaaaaaaaaaaaaaaaa
    and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    and ccccccccccccccccc
    and [dddddddddddddd, eeeeeeeeee, fffffffffffffff]
):
    pass

# Regression test for https://github.com/astral-sh/ruff/issues/6068
if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) or numpy and isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) and numpy or isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy and isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy or isinstance(ccccccccccc, dddddd)
):
    pass


if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) or (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy) and isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) and (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy) or isinstance(ccccccccccc, dddddd)
):
    pass


def test():
    return (
        isinstance(other, Mapping)
        and {k.lower(): v for k, v in self.items()}
        == {k.lower(): v for k, v in other.items()}
    )



if "_continue" in request.POST or (
    # Redirecting after "Save as new".
    "_saveasnew" in request.POST
    and self.save_as_continue
    and self.has_change_permission(request, obj)
):
    pass


if True:
    if False:
        if True:
            if (
                self.validate_max
                and self.total_form_count() - len(self.deleted_forms) > self.max_num
            ) or self.management_form.cleaned_data[
                TOTAL_FORM_COUNT
            ] > self.absolute_max:
                pass


if True:
    if (
        reference_field_name is None
        or
        # Unspecified to_field(s).
        to_fields is None
        or
        # Reference to primary key.
        (
            None in to_fields
            and (reference_field is None or reference_field.primary_key)
        )
        or
        # Reference to field.
        reference_field_name in to_fields
    ):
        pass


field = opts.get_field(name)
if (
    field.is_relation
    and
    # Generic foreign keys OR reverse relations
    ((field.many_to_one and not field.related_model) or field.one_to_many)
):
    pass


if True:
    return (
        filtered.exists()
        and
        # It may happen that the object is deleted from the DB right after
        # this check, causing the subsequent UPDATE to return zero matching
        # rows. The same result can occur in some rare cases when the
        # database returns zero despite the UPDATE being executed
        # successfully (a row is matched and updated). In order to
        # distinguish these two cases, the object's existence in the
        # database is again checked for if the UPDATE query returns 0.
        (filtered._update(values) > 0 or filtered.exists())
    )


if (self._proc is not None
    # has the child process finished?
    and self._returncode is None
    # the child process has finished, but the
    # transport hasn't been notified yet?
    and self._proc.poll() is None):
    pass

if (self._proc
    # has the child process finished?
    * self._returncode
    # the child process has finished, but the
    # transport hasn't been notified yet?
    + self._proc.poll()):
    pass
```

## Output
```python
if (
    self._proc
    # has the child process finished?
    and self._returncode
    # the child process has finished, but the
    # transport hasn't been notified yet?
    and self._proc.poll()
):
    pass

if (
    self._proc
    and self._returncode
    and self._proc.poll()
    and self._proc
    and self._returncode
    and self._proc.poll()
):
    pass

if (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaaaaaa
    and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
):
    pass


if (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
    and aaaaaaaaaaaaaaaaa
):
    pass


if [2222, 333] and [
    aaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbb,
    cccccccccccccccccccc,
    dddddddddddddddddddd,
    eeeeeeeeee,
]:
    pass

if [
    aaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbb,
    cccccccccccccccccccc,
    dddddddddddddddddddd,
    eeeeeeeeee,
] and [2222, 333]:
    pass

# Break right only applies for boolean operations with a left and right side
if (
    aaaaaaaaaaaaaaaaaaaaaaaaaa
    and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    and ccccccccccccccccc
    and [dddddddddddddd, eeeeeeeeee, fffffffffffffff]
):
    pass

# Regression test for https://github.com/astral-sh/ruff/issues/6068
if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
    or numpy
    and isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
    and numpy
    or isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
    or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
    and isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
    and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
    or isinstance(ccccccccccc, dddddd)
):
    pass


if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
    or (
        xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
    )
    and isinstance(ccccccccccc, dddddd)
):
    pass

if not (
    isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
    and (
        xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
    )
    or isinstance(ccccccccccc, dddddd)
):
    pass


def test():
    return isinstance(other, Mapping) and {k.lower(): v for k, v in self.items()} == {
        k.lower(): v for k, v in other.items()
    }


if "_continue" in request.POST or (
    # Redirecting after "Save as new".
    "_saveasnew" in request.POST
    and self.save_as_continue
    and self.has_change_permission(request, obj)
):
    pass


if True:
    if False:
        if True:
            if (
                self.validate_max
                and self.total_form_count() - len(self.deleted_forms) > self.max_num
            ) or self.management_form.cleaned_data[
                TOTAL_FORM_COUNT
            ] > self.absolute_max:
                pass


if True:
    if (
        reference_field_name is None
        or
        # Unspecified to_field(s).
        to_fields is None
        or
        # Reference to primary key.
        (None in to_fields and (reference_field is None or reference_field.primary_key))
        or
        # Reference to field.
        reference_field_name in to_fields
    ):
        pass


field = opts.get_field(name)
if (
    field.is_relation
    and
    # Generic foreign keys OR reverse relations
    ((field.many_to_one and not field.related_model) or field.one_to_many)
):
    pass


if True:
    return (
        filtered.exists()
        and
        # It may happen that the object is deleted from the DB right after
        # this check, causing the subsequent UPDATE to return zero matching
        # rows. The same result can occur in some rare cases when the
        # database returns zero despite the UPDATE being executed
        # successfully (a row is matched and updated). In order to
        # distinguish these two cases, the object's existence in the
        # database is again checked for if the UPDATE query returns 0.
        (filtered._update(values) > 0 or filtered.exists())
    )


if (
    self._proc is not None
    # has the child process finished?
    and self._returncode is None
    # the child process has finished, but the
    # transport hasn't been notified yet?
    and self._proc.poll() is None
):
    pass

if (
    self._proc
    # has the child process finished?
    * self._returncode
    # the child process has finished, but the
    # transport hasn't been notified yet?
    + self._proc.poll()
):
    pass
```



