This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amazingmo
Recipients amazingmo
Date 2021-01-12.01:20:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610414428.66.0.949606114531.issue42900@roundup.psfhosted.org>
In-reply-to
Content
Hello,

I expect the following code to run fine, but the assertion fails. dbg1 is 1, while dbg2 is 3.  I thought they would both be 3.
Note that the only difference between the expressions for dbg1 and dbg2 are the parentheses.
Please accept my apologies if this is expected behavior, but it came as a big surprise to me.


import json
if __name__ == "__main__":
    msg = '''
        {
        "Sync Setup Flags": {
            "Setup Sync": "Enable",
            "Generate Primary Sync": "Enable",
            "Backup Primary Sync": "Disable",
            "Follow Only": "Disable",
            "Use Local Clock": "Disable",
            "Set Active": "Disable"
        }
        }
        '''
    obj = json.loads(msg)
    dbg1 = \
        1 if obj["Sync Setup Flags"]["Setup Sync"] == "Enable" else 0 | \
        2 if obj["Sync Setup Flags"]["Generate Primary Sync"] == "Enable" else 0 | \
        4 if obj["Sync Setup Flags"]["Backup Primary Sync"] == "Enable" else 0 | \
        8 if obj["Sync Setup Flags"]["Follow Only"] == "Enable" else 0 | \
        16 if obj["Sync Setup Flags"]["Use Local Clock"] == "Enable" else 0 | \
        128 if obj["Sync Setup Flags"]["Set Active"] == "Enable" else 0
    dbg2 = \
        (1 if obj["Sync Setup Flags"]["Setup Sync"] == "Enable" else 0) | \
        (2 if obj["Sync Setup Flags"]["Generate Primary Sync"] == "Enable" else 0) | \
        (4 if obj["Sync Setup Flags"]["Backup Primary Sync"] == "Enable" else 0) | \
        (8 if obj["Sync Setup Flags"]["Follow Only"] == "Enable" else 0) | \
        (16 if obj["Sync Setup Flags"]["Use Local Clock"] == "Enable" else 0) | \
        (128 if obj["Sync Setup Flags"]["Set Active"] == "Enable" else 0)

    assert(dbg1 == dbg2)
History
Date User Action Args
2021-01-12 01:20:29amazingmosetrecipients: + amazingmo
2021-01-12 01:20:28amazingmosetmessageid: <1610414428.66.0.949606114531.issue42900@roundup.psfhosted.org>
2021-01-12 01:20:28amazingmolinkissue42900 messages
2021-01-12 01:20:28amazingmocreate