Skip to content

[flake8-bugbear] Mark fix unsafe when it would remove comments (B033)#22632

Merged
ntBre merged 1 commit intoastral-sh:mainfrom
leandrobbraga:bugfix/b033-unsafe-fix
Jan 17, 2026
Merged

[flake8-bugbear] Mark fix unsafe when it would remove comments (B033)#22632
ntBre merged 1 commit intoastral-sh:mainfrom
leandrobbraga:bugfix/b033-unsafe-fix

Conversation

@leandrobbraga
Copy link
Contributor

The B033 erroneously removes comments in safe fix.

By running

$ cargo run -p ruff  -- check --select B033 - << 'EOF'
{
  1,
  # comment
  1
}
EOF

We get:

Before

B033 [*] Sets should not contain duplicate item `1`
 --> -:4:3
  |
2 |   1,
3 |   # comment
4 |   1
  |   ^
5 | }
  |
help: Remove duplicate item

Found 1 error.
[*] 1 fixable with the `--fix` option.

After

B033 Sets should not contain duplicate item `1`
 --> -:4:3
  |
2 |   1,
3 |   # comment
4 |   1
  |   ^
5 | }
  |
help: Remove duplicate item

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Closes #22629

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 16, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@leandrobbraga leandrobbraga force-pushed the bugfix/b033-unsafe-fix branch from 7ec9fc4 to d5a52c3 Compare January 16, 2026 22:57
@leandrobbraga leandrobbraga force-pushed the bugfix/b033-unsafe-fix branch from d5a52c3 to 4ac9e7b Compare January 16, 2026 22:58
@amyreese amyreese requested a review from ntBre January 16, 2026 23:43
@amyreese amyreese added the fixes Related to suggested fixes for violations label Jan 16, 2026
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@ntBre ntBre changed the title [ruff] Fix B033 removing comments in safe fix [flake8-bugbear] Mark fix unsafe when it would remove comments (B033) Jan 17, 2026
@ntBre ntBre merged commit 20d80ed into astral-sh:main Jan 17, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safe fix for B033 can remove comments

3 participants