Author eric.snow
Recipients eric.snow, levinvm
Date 2016-10-28.18:25:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1477679145.49.0.969064240435.issue28550@psf.upfronthosting.co.za>
In-reply-to
Content
The syntax is working correctly.  Precedence rules are throwing you off.  It should be more clear if we use parentheses to demonstrate precedence explicitly.

You expected:

a, b = (obj.a, obj.b) if obj else [None, None]

However, what you wrote is equivalent to:

a, b = obj.a, (obj.b if obj else [None, None])

Hence the error about not finding "None.a" (when it resolves obj.a).  You can solve this by explicitly marking the precedence like I did in the "You expected" example above.  Sometimes precedence isn't clear, so when in doubt, use parentheses to make the precedence explicit.

I'm sorry this wasn't more clear.  Do you think any changes in Python's documentation would have helped you avoid this confusion?
History
Date User Action Args
2016-10-28 18:25:45eric.snowsetrecipients: + eric.snow, levinvm
2016-10-28 18:25:45eric.snowsetmessageid: <1477679145.49.0.969064240435.issue28550@psf.upfronthosting.co.za>
2016-10-28 18:25:45eric.snowlinkissue28550 messages
2016-10-28 18:25:45eric.snowcreate