Skip to content

Python implicit boolean conversion in logical operations bypasses try/except on 3.14.0rc1 #137288

Description

@justinjfu

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:

class Foo:
  def __bool__(self):
    raise NotImplementedError()

a = Foo()
b = Foo()

# Works
try:
  c = bool(a)
except:
  print("passed c = bool(a)")

# Fails
try:
  c = a or b
except:
  print("passed c = a or b")

Output on Python 3.12.3 (expected behavior):

passed c = bool(a)
passed c = a or b

Output on Python 3.14.0rc1:

passed c = bool(a)
Traceback (most recent call last):
  File "/Users/justinfu/code/test_bool.py", line 15, in <module>
    c = a or b
        ^^^^^^
  File "/Users/justinfu/code/test_bool.py", line 3, in __bool__
    raise NotImplementedError()
NotImplementedError

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. ethanfurman commented on Jul 31, 2025

    @ethanfurman
    Member

    Confirmed on LinuxMint.

  2. brianschubert commented on Jul 31, 2025

    @brianschubert
    Contributor

    Bisects to 78aeb38 (#124394), cc @iritkatriel

  3. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Jul 31, 2025
  4. self-assigned this
    on Aug 1, 2025
  5. added a commit that references this issue on Aug 1, 2025
  6. iritkatriel commented on Aug 1, 2025

    @iritkatriel
    Member

    Thank you @justinjfu for reporting and @brianschubert for bisecting. This is a nice little bug.

    Fix in #137310

  7. justinjfu commented on Aug 1, 2025

    @justinjfu
    Author

    Thank you for the quick fix!

  8. 7 remaining items

  9. added 7 commits that reference this issue on Aug 12, 2025
  10. added 2 commits that reference this issue on Aug 12, 2025
  11. added a commit that references this issue on Aug 12, 2025
  12. added 2 commits that reference this issue on Aug 19, 2025
  13. added 2 commits that reference this issue on Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)release-blockertype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions