Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Closed
Description
Bug report
Bug description:
Throwing an exception during an implicit cast to a boolean as part of a logical operation (or,and) bypasses surrounding try/except statements.
The following example works on Python 3.12.3 but fails on Python 3.14.0rc1:
Example:
classFoo:def__bool__(self):raiseNotImplementedError()a=Foo()b=Foo()# Workstry:c=bool(a)except:print("passed c = bool(a)")# Failstry:c=aorbexcept:print("passed c = a or b")
Output on Python 3.12.3 (expected behavior):
passed c = bool(a)passed c = a or bOutput on Python 3.14.0rc1:
passed c = bool(a)Traceback (most recent call last): File"/Users/justinfu/code/test_bool.py", line15, in<module> c= aor b^^^^^^ File"/Users/justinfu/code/test_bool.py", line3, in__bool__raiseNotImplementedError()NotImplementedError
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-137288: Fix bug where boolean expressions are not associated with the correct exception handler #137310
- [3.14] gh-137288: Fix bug where boolean expressions are not associated with the correct exception handler (GH-137310). #137427
- gh-137288: Fix Python version in magic number comment #137664
- gh-137288: Update 3.14 magic numbers #137665
- [3.14] gh-137288: Update version in magic number log (GH-137665) #137667
Metadata
Metadata
Assignees
Labels
Projects
Status
Done