Skip to content

formatter: Two iterations required to converge on specific comment + slice case #10355

@aneeshusa

Description

@aneeshusa

Tested on ruff v0.3.2 and main (dacec73). No ruff config.
Minimized from a file at $WORK; this cropped up during one of my final rebases to switch to ruff.
Not a blocker since the final formatting is stable.
black 24.2.0 accepts both the original and final style;
it rewrites the intermediate style to the final style.

Input:

repro(
    "some long string that takes up some space"
)[  # some long comment also taking up space
    0
]

1st run of ruff gives:

repro(
    "some long string that takes up some space"
)[0]  # some long comment also taking up space

2nd and beyond runs give:

repro("some long string that takes up some space")[
    0
]  # some long comment also taking up space
Script used
#!/usr/bin/env bash

# no errexit
set -o nounset
set -o pipefail

tmp_dir="$(mktemp -d)"
cleanup() {
    rm -rf "${tmp_dir}"
}
trap cleanup EXIT INT QUIT TERM

cat >"${tmp_dir}/repro.py" <<EOF
repro(
    "some long string that takes up some space"
)[  # some long comment also taking up space
    0
]
EOF

cd ~/code/ruff
git checkout "${1}"
ruff=(cargo run --quiet --package=ruff --)

echo -e '\nStarting hash of file'
(cd "${tmp_dir}" && sha256sum "./repro.py")
cat "${tmp_dir}/repro.py"

echo -e '\nFirst run'
"${ruff[@]}" format --isolated --target-version py310 --no-cache "${tmp_dir}/repro.py"
(cd "${tmp_dir}" && sha256sum "./repro.py")
cat "${tmp_dir}/repro.py"

echo -e '\nSecond run'
"${ruff[@]}" format --isolated --target-version py310 --no-cache "${tmp_dir}/repro.py"
(cd "${tmp_dir}" && sha256sum "./repro.py")
cat "${tmp_dir}/repro.py"

echo -e '\nThird run'
"${ruff[@]}" format --isolated --target-version py310 --no-cache "${tmp_dir}/repro.py"
(cd "${tmp_dir}" && sha256sum "./repro.py")

Didn't see any specific issues for this non-single-step-convergence, let me know if I missed one.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingformatterRelated to the formatter

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions