Eric Snow added the comment:

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?

----------
nosy: +eric.snow
resolution:  -> not a bug
stage:  -> resolved
status: open -> pending
type: crash -> behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28550>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to