Author stestagg
Recipients Mark.Shannon, Mohamed_Atef, stestagg
Date 2021-01-11.22:35:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610404519.53.0.728180640085.issue42899@roundup.psfhosted.org>
In-reply-to
Content
Apologies, script should have read:
class B:
     def __bool__(self):
         print("bool(B)")
         raise AttributeError("don't do that!")

b = B()
try:
   if b:
        pass
except AttributeError:
   print("GOT ERROR")
   raise IndexError("Should GET THIS")

print("SHOULDN'T GET THIS")


---

The DIS before the change for this code is:
BEFORE:
  1           0 LOAD_BUILD_CLASS
              2 LOAD_CONST               0 (<code object B at 0x7ff45711e710, file "<dis>", line 1>)
              4 LOAD_CONST               1 ('B')
              6 MAKE_FUNCTION            0
              8 LOAD_CONST               1 ('B')
             10 CALL_FUNCTION            2
             12 STORE_NAME               0 (B)

  6          14 LOAD_NAME                0 (B)
             16 CALL_FUNCTION            0
             18 STORE_NAME               1 (b)

  7          20 SETUP_FINALLY            8 (to 30)

  8          22 LOAD_NAME                1 (b)
             24 POP_JUMP_IF_FALSE       26

  9     >>   26 POP_BLOCK
             28 JUMP_FORWARD            30 (to 60)

 10     >>   30 DUP_TOP
             32 LOAD_NAME                2 (AttributeError)
             34 JUMP_IF_NOT_EXC_MATCH    58
             36 POP_TOP
             38 POP_TOP
             40 POP_TOP

 11          42 LOAD_NAME                3 (print)
             44 LOAD_CONST               2 ('GOT ERROR')
             46 CALL_FUNCTION            1
             48 POP_TOP

 12          50 LOAD_NAME                4 (IndexError)
             52 LOAD_CONST               3 ('Should GET THIS')
             54 CALL_FUNCTION            1
             56 RAISE_VARARGS            1
        >>   58 RERAISE

 14     >>   60 LOAD_NAME                3 (print)
             62 LOAD_CONST               4 ("SHOULDN'T GET THIS")
             64 CALL_FUNCTION            1
             66 POP_TOP
             68 LOAD_CONST               5 (None)
             70 RETURN_VALUE

Disassembly of <code object B at 0x7ff45711e710, file "<dis>", line 1>:
  1           0 LOAD_NAME                0 (__name__)
              2 STORE_NAME               1 (__module__)
              4 LOAD_CONST               0 ('B')
              6 STORE_NAME               2 (__qualname__)

  2           8 LOAD_CONST               1 (<code object __bool__ at 0x7ff45711e660, file "<dis>", line 2>)
             10 LOAD_CONST               2 ('B.__bool__')
             12 MAKE_FUNCTION            0
             14 STORE_NAME               3 (__bool__)
             16 LOAD_CONST               3 (None)
             18 RETURN_VALUE

Disassembly of <code object __bool__ at 0x7ff45711e660, file "<dis>", line 2>:
  3           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 ('bool(B)')
              4 CALL_FUNCTION            1
              6 POP_TOP

  4           8 LOAD_GLOBAL              1 (AttributeError)
             10 LOAD_CONST               2 ("don't do that!")
             12 CALL_FUNCTION            1
             14 RAISE_VARARGS            1


----
Afterwards, tehre's a single change:

8 becomes:

8          22 LOAD_NAME                1 (b)
             24 POP_TOP
History
Date User Action Args
2021-01-11 22:35:19stestaggsetrecipients: + stestagg, Mark.Shannon, Mohamed_Atef
2021-01-11 22:35:19stestaggsetmessageid: <1610404519.53.0.728180640085.issue42899@roundup.psfhosted.org>
2021-01-11 22:35:19stestagglinkissue42899 messages
2021-01-11 22:35:19stestaggcreate