
On 2015-10-01 19:50, Random832 wrote:
On Thu, Oct 1, 2015, at 14:36, MRAB wrote:
It's _not_ guaranteed that there'll be an exception if a is None; None does have _some_ attributes.
Well, it hasn't got a "d" attribute, but point taken. However, wanting to build expressions like this that will sometimes operate on the attributes of None and other times operate on the attributes of the non-None object normally expected to be present seems like an *extremely* obscure thing to want.
'and' and 'or' don't escape parentheses. I'd take it as a general rule that short-circuiting doesn't escape parentheses.
Sure they do. In what way is (a and b) and c different from a and b and c? Heck, (a and b) and (c and d) even compiles to the same bytecode as other groupings [demonstrating it has the same actual semantics] *even though it is a different AST*. But even if it didn't, it would just be jumping to another jump opcode.
If a is falsy, it short-circuits "a and b". The parenthesised expression returns a falsy result. That falsy result then short-circuits "(a and b) and c". It happens to show the same behaviour as "a and b and c" and can be optimised to that. Well, that's my opinion, anyway!
It doesn't escape being mixed with a different kind of expression, which is sometimes accomplished with parentheses, but that's not really the same thing.