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

Steven D'Aprano steve at pearwood.info
Fri Mar 30 06:50:27 EDT 2018


On Fri, Mar 30, 2018 at 01:29:53PM +0300, Serhiy Storchaka wrote:
> 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.

Assuming that bool is the built-in, and hasn't been shadowed or 
monkey-patched.


-- 
Steve


More information about the Python-Dev mailing list