Skip to content

[flake8-bugbear] Fix misleading description for B904#23731

Merged
amyreese merged 2 commits intoastral-sh:mainfrom
sososonia-cyber:fix/b904-documentation
Mar 5, 2026
Merged

[flake8-bugbear] Fix misleading description for B904#23731
amyreese merged 2 commits intoastral-sh:mainfrom
sososonia-cyber:fix/b904-documentation

Conversation

@sososonia-cyber
Copy link
Copy Markdown
Contributor

@sososonia-cyber sososonia-cyber commented Mar 5, 2026

Summary

This PR fixes the misleading description for the B904 rule (raise-without-from-inside-except).

The Issue

The original documentation incorrectly stated that without a 'from' clause, exceptions would not be chained. However, Python implicitly chains exceptions by setting __context__.

The Fix

The fix clarifies that:

  • Using from explicitly sets __cause__ (recommended)
  • Without from, Python still chains via __context__ but debugging is slightly harder

Fixes: #22541

The original description incorrectly stated that without a 'from' clause,
exceptions would not be chained. However, Python implicitly chains exceptions
by setting __context__. This fix clarifies that:
- Using 'from' explicitly sets __cause__ (recommended)
- Without 'from', Python still chains via __context__ but debugging is harder

Fixes: astral-sh#8736
@astral-sh-bot astral-sh-bot bot requested a review from amyreese March 5, 2026 07:33
@ntBre
Copy link
Copy Markdown
Contributor

ntBre commented Mar 5, 2026

The linked issue has already been closed, but this might fix #22541 instead. I'll leave the review to Amy.

@ntBre ntBre added the documentation Improvements or additions to documentation label Mar 5, 2026
@amyreese amyreese enabled auto-merge (squash) March 5, 2026 22:58
@amyreese amyreese changed the title docs: Fix misleading description for B904 rule [flake8-bugbear] Fix misleading description for B904 rule Mar 5, 2026
@amyreese amyreese changed the title [flake8-bugbear] Fix misleading description for B904 rule [flake8-bugbear] Fix misleading description for B904 Mar 5, 2026
@amyreese amyreese merged commit 3880c50 into astral-sh:main Mar 5, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading documentation for B904: raise-without-from-inside-except

3 participants