New submission from Steve Stagg <stest...@gmail.com>:

This was raised by Mats Wichmann <m...@python.org>  on the python-dev list.

Commit : c71581c7a4192e6ba9a79eccc583aaadab300efa
bpo-42615: Delete redundant jump instructions that only bypass empty blocks 
(GH-23733)

appears to have changed the behaviour of the following code:

class B:
     def __bool__(self):
         raise AttributeError("don't do that!")

b = B()
try:
   if b:
        pass
except AttributeError:
   print("HI")


Before the change, the output is:

bool(B)
GOT ERROR
Traceback (most recent call last):
  File "../test.py", line 8, in <module>
    if b:
  File "../test.py", line 4, in __bool__
    raise AttributeError("don't do that!")
AttributeError: don't do that!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../test.py", line 12, in <module>
    raise IndexError("Should GET THIS")
IndexError: Should GET THIS


After the change, just:

SHOULDN'T GET THIS

It seems like the entire branch is being eliminated prematurely, but maybe only 
when the statement is wrapped in a try-except?

----------
messages: 384867
nosy: Mark.Shannon, m, stestagg
priority: normal
severity: normal
status: open
title: Possible regression introduced by bpo-42615
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42899>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to