[Python-Dev] Subtle difference between f-strings and str.format()

Serhiy Storchaka storchaka at gmail.com
Fri Mar 30 06:29:53 EDT 2018


29.03.18 18:06, Terry Reedy пише:
> On 3/28/2018 11:27 AM, Serhiy Storchaka wrote:
>> The optimizer already changes semantic. Non-optimized "if a and True:" 
>> would call bool(a) twice, but optimized code calls it only once.
> 
> Perhaps Ref 3.3.1 object.__bool__ entry, after " should return False or 
> True.", should say something like "Should not have side-effects, as 
> redundant bool calls may be optimized away (bool(bool(ob)) should have 
> the same result as bool(ob))."

Do you meant that it should be idempotent operation? Because 
bool(bool(ob)) always have the same result as bool(ob)) if bool(ob) 
returns True or False.



More information about the Python-Dev mailing list