Author nedbat
Recipients aldwinaldwin, miss-islington, ned.deily, nedbat, pablogsal, scoder, serhiy.storchaka, xtreak
Date 2019-07-05.20:54:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562360068.77.0.303837250632.issue37500@roundup.psfhosted.org>
In-reply-to
Content
To add to the confusion, the treatment of "if __debug__:" and "if not __debug__:" is now asymmetric:

Here is debug.py:

import dis
import sys
print(sys.version)

def f():
    if __debug__:
        print("debug")
    else:
        print("not debug")
    if not __debug__:
        print("NOT DEBUG")
    else:
        print("DEBUG")

dis.dis(f)


$ python3.8 /tmp/debug.py
3.8.0b2 (default, Jul  4 2019, 22:38:04)
[Clang 10.0.0 (clang-1000.10.44.4)]
  7           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 ('debug')
              4 CALL_FUNCTION            1
              6 POP_TOP

 10           8 LOAD_CONST               2 (False)
             10 POP_JUMP_IF_FALSE       22

 11          12 LOAD_GLOBAL              0 (print)
             14 LOAD_CONST               3 ('NOT DEBUG')
             16 CALL_FUNCTION            1
             18 POP_TOP
             20 JUMP_FORWARD             8 (to 30)

 13     >>   22 LOAD_GLOBAL              0 (print)
             24 LOAD_CONST               4 ('DEBUG')
             26 CALL_FUNCTION            1
             28 POP_TOP
        >>   30 LOAD_CONST               0 (None)
             32 RETURN_VALUE

$ python3.8 -O /tmp/debug.py
3.8.0b2 (default, Jul  4 2019, 22:38:04)
[Clang 10.0.0 (clang-1000.10.44.4)]
  6           0 LOAD_CONST               1 (False)
              2 POP_JUMP_IF_FALSE       14

  7           4 LOAD_GLOBAL              0 (print)
              6 LOAD_CONST               2 ('debug')
              8 CALL_FUNCTION            1
             10 POP_TOP
             12 JUMP_FORWARD             8 (to 22)

  9     >>   14 LOAD_GLOBAL              0 (print)
             16 LOAD_CONST               3 ('not debug')
             18 CALL_FUNCTION            1
             20 POP_TOP

 11     >>   22 LOAD_GLOBAL              0 (print)
             24 LOAD_CONST               4 ('NOT DEBUG')
             26 CALL_FUNCTION            1
             28 POP_TOP
             30 LOAD_CONST               0 (None)
             32 RETURN_VALUE

In 3.7 (and earlier) the behavior was balanced:

$ python3.7 /tmp/debug.py
3.7.3 (default, Apr 10 2019, 10:27:53)
[Clang 10.0.0 (clang-1000.10.44.4)]
  7           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 ('debug')
              4 CALL_FUNCTION            1
              6 POP_TOP

 13           8 LOAD_GLOBAL              0 (print)
             10 LOAD_CONST               2 ('DEBUG')
             12 CALL_FUNCTION            1
             14 POP_TOP
             16 LOAD_CONST               0 (None)
             18 RETURN_VALUE

$ python3.7 -O /tmp/debug.py
3.7.3 (default, Apr 10 2019, 10:27:53)
[Clang 10.0.0 (clang-1000.10.44.4)]
  9           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 ('not debug')
              4 CALL_FUNCTION            1
              6 POP_TOP

 11           8 LOAD_GLOBAL              0 (print)
             10 LOAD_CONST               2 ('NOT DEBUG')
             12 CALL_FUNCTION            1
             14 POP_TOP
             16 LOAD_CONST               0 (None)
             18 RETURN_VALUE


Is this really the desired behavior?
History
Date User Action Args
2019-07-05 20:54:28nedbatsetrecipients: + nedbat, scoder, ned.deily, serhiy.storchaka, pablogsal, miss-islington, xtreak, aldwinaldwin
2019-07-05 20:54:28nedbatsetmessageid: <1562360068.77.0.303837250632.issue37500@roundup.psfhosted.org>
2019-07-05 20:54:28nedbatlinkissue37500 messages
2019-07-05 20:54:28nedbatcreate