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

Cache causes confusing behavior when running with and without "--unstable" #4465

Closed
twitchard opened this issue Sep 27, 2024 · 1 comment · Fixed by #4466
Closed

Cache causes confusing behavior when running with and without "--unstable" #4465

twitchard opened this issue Sep 27, 2024 · 1 comment · Fixed by #4466
Labels
T: bug Something isn't working

Comments

@twitchard
Copy link

Describe the bug

If you run black without --unstable on a file and then run it with --unstable, it won't apply changes that should be applied by --unstable.

To Reproduce

black --version
python_code='long_line = "      20        30        40        50        60        70        80        90        100       110       120       130       140"'
echo "$python_code" > my_file.py
echo "Formatting without --unstable..."
black -l 120 my_file.py
cat my_file.py

echo "Formatting with --unstable..."
black -l 120 --unstable my_file.py
cat my_file.py
echo "Adding a newline to invalidate the cache..."
echo -e "\n" >> my_file.py
echo "Formatting with --unstable again..."
black -l 120 --unstable my_file.py
cat my_file.py

for me outputs

black, 24.8.0 (compiled: yes)
Python (CPython) 3.12.4
Formatting without --unstable...
All done! ✨ 🍰 ✨
1 file left unchanged.
long_line = "      20        30        40        50        60        70        80        90        100       110       120       130       140"
Formatting with --unstable...
All done! ✨ 🍰 ✨
1 file left unchanged.
long_line = "      20        30        40        50        60        70        80        90        100       110       120       130       140"
Adding a newline to invalidate the cache...
Formatting with --unstable again...
reformatted my_file.py

All done! ✨ 🍰 ✨
1 file reformatted.
long_line = (
    "      20        30        40        50        60        70        80        90        100       110       120     "
    "  130       140"
)

Expected behavior

  • Adding --unstable to the command should cause black to ignore cache results that were produced without --unstable.
  • To me "1 file left unchanged" misleadingly suggests that black looked at the file and determined there were no changes to make. A wording like "1 unchanged file ignored" would have helped me understand a cache was in play.
  • Similarly the fact that black --help makes no mention of a cache / has no flag to bypass was a barrier to me understanding that this was a possibility.

Environment

  • Black's version: 24.8.0
  • OS and Python version: 3.12.4, Mac OS
@twitchard twitchard added the T: bug Something isn't working label Sep 27, 2024
JelleZijlstra added a commit to JelleZijlstra/black that referenced this issue Sep 27, 2024
@JelleZijlstra
Copy link
Collaborator

Thanks, we were missing --unstable in the cache key. Submitted a fix in #4466.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants