Author serhiy.storchaka
Recipients Mark.Shannon, Mohamed_Atef, gregory.p.smith, pablogsal, serhiy.storchaka, stestagg
Date 2021-01-12.10:00:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610445646.68.0.591634693473.issue42899@roundup.psfhosted.org>
In-reply-to
Content
I am not sure that it should be fixed.

We already cut corners in similar cases and did this for years, and it always was okay. In the following example bool(a) is only called once:

    if a and b:
        f()

  1           0 LOAD_NAME                0 (a)
              2 POP_JUMP_IF_FALSE       14
              4 LOAD_NAME                1 (b)
              6 POP_JUMP_IF_FALSE       14

  2           8 LOAD_NAME                2 (f)
             10 CALL_FUNCTION            0
             12 POP_TOP
        >>   14 LOAD_CONST               0 (None)
             16 RETURN_VALUE

It differs from the case of using temporary variable (optimization does not work here):

    t = a and b
    if t:
        f()

  1           0 LOAD_NAME                0 (a)
              2 JUMP_IF_FALSE_OR_POP     6
              4 LOAD_NAME                1 (b)
        >>    6 STORE_NAME               2 (t)

  2           8 LOAD_NAME                2 (t)
             10 POP_JUMP_IF_FALSE       18

  3          12 LOAD_NAME                3 (f)
             14 CALL_FUNCTION            0
             16 POP_TOP
        >>   18 LOAD_CONST               0 (None)
             20 RETURN_VALUE

(BTW, Python 3.10 produces less optimal code for that examples)
History
Date User Action Args
2021-01-12 10:00:46serhiy.storchakasetrecipients: + serhiy.storchaka, gregory.p.smith, Mark.Shannon, Mohamed_Atef, pablogsal, stestagg
2021-01-12 10:00:46serhiy.storchakasetmessageid: <1610445646.68.0.591634693473.issue42899@roundup.psfhosted.org>
2021-01-12 10:00:46serhiy.storchakalinkissue42899 messages
2021-01-12 10:00:46serhiy.storchakacreate