[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread MRAB
On 2021-11-29 00:52, Christopher Barker wrote: I will frequently do simple computation with literals to make my code more clear: t = 2 * 3600  # 2 hours in seconds But I see no need to optimize this kind of thing -- it would never be in a tight loop. The suggestion was specifically about

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Chris Angelico
On Mon, Nov 29, 2021 at 10:11 AM Rob Cliffe via Python-Dev wrote: > > I am slightly surprised that it seems to be *easier* to fold selected > constant expressions than to have more generic code to fold them all. > Or at least, all those that don't contain containers, such as > 1 in [0,1,2]

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Eric V. Smith
On 11/28/2021 7:52 PM, Christopher Barker wrote: I will frequently do simple computation with literals to make my code more clear: t = 2 * 3600  # 2 hours in seconds That is optimized as you'd hope. Tested in 3.8: >>> dis.dis("t = 2 * 3600")   1   0 LOAD_CONST   0 (7200)

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Christopher Barker
I will frequently do simple computation with literals to make my code more clear: t = 2 * 3600 # 2 hours in seconds But I see no need to optimize this kind of thing -- it would never be in a tight loop. -CHB On Sun, Nov 28, 2021 at 3:06 PM Rob Cliffe via Python-Dev < python-dev@python.org>

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Rob Cliffe via Python-Dev
I am slightly surprised that it seems to be *easier* to fold selected constant expressions than to have more generic code to fold them all. Or at least, all those that don't contain containers, such as     1 in [0,1,2] Rob Cliffe On 28/11/2021 21:10, Eric V. Smith wrote: On Nov 28, 2021, at

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Eric V. Smith
> On Nov 28, 2021, at 3:03 PM, Serhiy Storchaka wrote: > > 28.11.21 17:13, Skip Montanaro пише: >>> That is not entirely true: >>> https://github.com/python/cpython/pull/29639#issuecomment-974146979 >> >> The only places I've seen "if 0:" or "if False:" in live code was for >> debugging.

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Serhiy Storchaka
27.11.21 15:47, Jeremiah Vivian пише: > Many operations involving two literals are optimized (to a certain level). So > it sort of surprises me that literal comparisons are not optimized and > literal contains only convert the right operand to a constant if possible. > I'd like to implement

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Serhiy Storchaka
28.11.21 17:13, Skip Montanaro пише: >> That is not entirely true: >> https://github.com/python/cpython/pull/29639#issuecomment-974146979 > > The only places I've seen "if 0:" or "if False:" in live code was for > debugging. Optimizing that hardly seems necessary. In any case, the > original

[Python-Dev] Re: Remove asyncore, asynchat and smtpd modules

2021-11-28 Thread Steve Holden
Speaking as the author of the doc pages, I think I can safely say that anyone who was smart enough to use asyncore/asychat back in the day (I used it in "Python Web Programming") is almost certainly smart enough to have migrated away from them long ago. They were an interesting approach to

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Skip Montanaro
> That is not entirely true: > https://github.com/python/cpython/pull/29639#issuecomment-974146979 The only places I've seen "if 0:" or "if False:" in live code was for debugging. Optimizing that hardly seems necessary. In any case, the original comment was about comparisons of two constants. I

[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Mark Shannon
On 28/11/2021 6:28 am, raymond.hettin...@gmail.com wrote: For the benefit of the audience on python-dev, you should also mention that this proposal and associated PR has been twice discussed and rejected on the tracker: https://bugs.python.org/issue45907