On Thu, May 28, 2020 at 11:40:52AM +0300, Serhiy Storchaka wrote:

> Why do you think it will be faster? `a == b == c` is the same as `a == b 
> and b == c`, but a tiny bit slower.

That surprises me. I thought that the big advantage of chained 
comparisons is that results are only evaluated once.

    a == expensive_expression == c

should be faster than calculating the expensive expression twice:

    a == expensive_expression and expensive_expression == c

and even if the expression is just a name lookup, isn't one name lookup 
cheaper than two?

> You always can write
> 
>     self.assertTrue(a == b == c)
> 
> But the advantage of two separate assertions is that you know what 
> comparison fails if it fails and get more informative report.

I agree that this is a very good argument for writing separate 
assertions.


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GYVHSAH3VQY5AXKSW2PNKHUURSDHTDLP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to