Skip to content

Fix bad-exception-cause false positive when the cause's bases are unknown - #11399

Merged
Pierre-Sassoulas merged 2 commits into
pylint-dev:mainfrom
kdelay:fix/exception-cause-unknown-bases
Sep 13, 2026
Merged

Pierre-Sassoulas merged 2 commits into
pylint-dev:mainfrom
kdelay:fix/exception-cause-unknown-bases

Conversation

@kdelay

@kdelay kdelay commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Type of Changes

Type
✓ 🐛 Bug fix

Description

inherit_from_std_ex looks for BaseException in ancestors(), so a class whose base cannot be inferred (a C extension, a conditional import) reads as a non-exception.

raising-non-exception and catching-non-exception already pair that helper with has_known_bases. _check_bad_exception_cause did not.

Reproduced on anyio/to_interpreter.py:55, where ExecutionFailed derives from _interpreters.InterpreterError and ancestors() comes back empty:

except ExecutionFailed as exc:
    raise BrokenWorkerInterpreter(exc.excinfo) from exc

E0705 fires there while catching-non-exception stays silent on the same handler.

inherit_from_std_ex walks ancestors() looking for BaseException, so a
class whose base cannot be inferred (a C extension, a conditional
import) looks like a non-exception and `raise ... from exc` is flagged.
The sibling checks raising-non-exception and catching-non-exception
already guard that case with has_known_bases, but
_check_bad_exception_cause did not.

Reproduced on anyio/to_interpreter.py, whose ExecutionFailed derives
from _interpreters.InterpreterError.
@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.48%. Comparing base (af3930e) to head (5dfc4ae).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #11399   +/-   ##
=======================================
  Coverage   96.48%   96.48%           
=======================================
  Files         178      178           
  Lines       20407    20409    +2     
=======================================
+ Hits        19689    19691    +2     
  Misses        718      718           
Files with missing lines Coverage Δ
pylint/checkers/exceptions.py 99.15% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🤖 Effect of this PR on checked open source code: 🤖

Effect on sentry:

Removed messages:

Details
  1. bad-exception-cause:
    Exception cause set to something which is not an exception, nor None
    https://github.com/getsentry/sentry/blob/7a701584e61d8a093132eb37c45fd0359c1652ee/src/sentry/shared_integrations/client/base.py#L270

This comment was generated for commit 5dfc4ae

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/4.1.x labels Sep 13, 2026
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.9 milestone Sep 13, 2026

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you

@Pierre-Sassoulas
Pierre-Sassoulas merged commit a443dd3 into pylint-dev:main Sep 13, 2026
52 checks passed
Pierre-Sassoulas added a commit that referenced this pull request Sep 14, 2026
…hen the cause's bases are unknown (#11419)

Fix bad-exception-cause false positive when the cause's bases are unknown (#11399)

inherit_from_std_ex walks ancestors() looking for BaseException, so a
class whose base cannot be inferred (a C extension, a conditional
import) looks like a non-exception and `raise ... from exc` is flagged.
The sibling checks raising-non-exception and catching-non-exception
already guard that case with has_known_bases, but
_check_bad_exception_cause did not.

Reproduced on anyio/to_interpreter.py, whose ExecutionFailed derives
from _interpreters.InterpreterError.

(cherry picked from commit a443dd3)

Co-authored-by: kdelay <90545043+kdelay@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported False Positive 🦟 A message is emitted but nothing is wrong with the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants