Skip to content

[flake8-bugbear] Report the method name and a more precise range (B005) - #27050

Merged
ntBre merged 4 commits into
astral-sh:mainfrom
Viicos:vp/b005
Oct 2, 2026
Merged

ntBre merged 4 commits into
astral-sh:mainfrom
Viicos:vp/b005

Conversation

@Viicos

@Viicos Viicos commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

The diagnostic message now reports the method name, and range was adapted to be more precise and only
cover the call and argument.

Fixes #27085.

Summary

I got confused by one report of this rule. This is how it looks before this PR:

B005 Using `.strip()` with multi-character strings is misleading
    |
215 | key = ""
216 |
217 | key = key.strip("--").lstrip('--')
    |       ^^^^^^^^^^^^^^^
    |

B005 Using `.strip()` with multi-character strings is misleading
    |
215 | key = ""
216 |
217 | key = key.strip("--").lstrip('--')
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

Test Plan

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 21, 2026 18:10
@astral-sh-bot

astral-sh-bot Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+15 -15 violations, +0 -0 fixes in 3 projects; 55 projects unchanged)

apache/airflow (+4 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL

- providers/celery/src/airflow/providers/celery/executors/default_celery.py:263:13: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ providers/celery/src/airflow/providers/celery/executors/default_celery.py:263:52: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
- providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/custom_object_launcher.py:162:56: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/custom_object_launcher.py:162:87: strip-with-multi-characters Using `.rstrip()` with multi-character strings is misleading
- providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/custom_object_launcher.py:171:27: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/custom_object_launcher.py:171:60: strip-with-multi-characters Using `.rstrip()` with multi-character strings is misleading
- scripts/ci/prek/lint_dockerfile.py:57:15: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ scripts/ci/prek/lint_dockerfile.py:57:20: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading

binary-husky/gpt_academic (+9 -9 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- crazy_functions/Audio_Assistant.py:24:32: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ crazy_functions/Audio_Assistant.py:24:34: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
- crazy_functions/Latex_Function.py:465:18: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ crazy_functions/Latex_Function.py:465:27: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading
- request_llms/bridge_moss.py:236:32: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ request_llms/bridge_moss.py:236:41: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
- request_llms/bridge_moss.py:242:29: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ request_llms/bridge_moss.py:242:38: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
- request_llms/bridge_qianfan.py:111:19: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ request_llms/bridge_qianfan.py:111:33: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading
- themes/gradios.py:16:25: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ themes/gradios.py:16:31: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading
- themes/gradios.py:18:25: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ themes/gradios.py:18:31: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading
- themes/gradios.py:33:29: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ themes/gradios.py:33:35: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading
- themes/gradios.py:35:29: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ themes/gradios.py:35:35: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading

bokeh/bokeh (+2 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL

- src/bokeh/plotting/_graph.py:141:20: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ src/bokeh/plotting/_graph.py:141:22: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading
- src/bokeh/plotting/_graph.py:141:78: strip-with-multi-characters Using `.strip()` with multi-character strings is misleading
+ src/bokeh/plotting/_graph.py:141:80: strip-with-multi-characters Using `.lstrip()` with multi-character strings is misleading

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
strip-with-multi-characters 30 15 15 0 0

The diagnostic message now reports the method name,
and range was adapted to be more precise and only
cover the call and argument.
@ntBre

ntBre commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Is this related to an open issue? Changing the range of a rule is almost always a breaking change because it changes where suppression comments work. I have to think about it a bit more, but this does look like an improvement to me. However, we need to make it a preview change, again because it can break suppression comments.

@Viicos

Viicos commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I didn't know this would be considered breaking. As such, I opened #27085.

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! This seems like a pretty clear improvement to me, we just need to make it a preview change, as I mentioned before.

Comment thread crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs Outdated
@ntBre ntBre added preview Related to preview-mode features diagnostics Diagnostic messages, annotations, fixes & rendering infra--not for PRs that just add new diagnostics labels Jul 27, 2026
Viicos and others added 3 commits July 29, 2026 14:54
# Conflicts:
#	crates/ruff_linter/src/preview.rs
#	crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs
@ntBre ntBre changed the title B005: Reflect method name in diagnostic, adapt range [flake8-bugbear] Report the method name and a more precise range in B005 diagnostics Oct 2, 2026
@ntBre ntBre changed the title [flake8-bugbear] Report the method name and a more precise range in B005 diagnostics [flake8-bugbear] Report the method name and a more precise range (B005) Oct 2, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@ntBre
ntBre enabled auto-merge (squash) October 2, 2026 19:38
@ntBre
ntBre merged commit 678d6b9 into astral-sh:main Oct 2, 2026
51 checks passed
@Viicos
Viicos deleted the vp/b005 branch October 2, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Diagnostic messages, annotations, fixes & rendering infra--not for PRs that just add new diagnostics preview Related to preview-mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

B005: Reflect method name in diagnostic, adapt range

2 participants