[Python-Dev] Optimizing literal comparisons and contains

2021-11-27 Thread 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 optimizations for these especially for the literal contains. There is 
a TODO in the ast optimizer for literal comparisons as well, and that's another 
reason I would like to have these added.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/5I2GXLMVZ6OOLACL2BB2ER4L2RKEGWIJ/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-11-27 Thread Skip Montanaro
> 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 optimizations for these especially for the literal 
> contains. There is a TODO in the ast optimizer for literal comparisons as 
> well, and that's another reason I would like to have these added.

Though not having paid much attention to this over the years, I'm
pretty sure I've seen the topic float past from time-to-time. As I
recall, optimizing expressions involving two constants isn't a big win
in Python because that sort of expression occurs rarely in anything
other than test code. In C/C++ and its cousins, preprocessors
routinely expand names to constants, so

2 == 2

might well be seen by the compiler even though the author actually wrote

  MUMBLE == FRAZZLE

If a Python programmer wrote such an expression, MUMBLE and FRAZZLE
would be names bound to a particular object, and could — theoretically
— be rebound at runtime, so such an expression couldn't safely be
optimized.

So, while you could optimize expressions involving just constants, the
benefit would be exceedingly small compared to the effort to write and
maintain the optimization code.

Skip
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/4TFW3Q2X42XKP4IK263ZXOGAZ3XXYUH4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: The current state of typing PEPs

2021-11-27 Thread Christopher Barker
On Fri, Nov 26, 2021 at 5:47 PM Jim J. Jewett  wrote:

> Steven D'Aprano wrote:
> > Maybe PEP 563 could include a decorator in the typing module to
> > destringify all the annotations in a class or function?
>
> If it were in an annotations module, that would probably be sufficient.
>
> If it is in typing, then it is a very heavyweight dependency --


As of Py 3.10 there is:

inspect.get_annotations

one could write a decorator around that, but I think the real question is
when do you want the annotations to be "finalized"?

-CHB



heavy enough that even the people actually using that module for
> development (and not for production runs) are worried about the costs.  If
> the costs of the typing module are that high, it is not acceptable to
> impose them on people not otherwise using the module.
>
> -jJ
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/ZQHP24T2PKRTDBGZ36KLBHLLOKITP5ON/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/OID2CGJ2L5IA7WGDRPO45BAPECFGWO7B/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-11-27 Thread raymond . hettinger
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
   https://bugs.python.org/issue45843

The response just given by Skip pretty much matches the comments already given 
by Batuhan, Pablo, and Serhiy.  So far, no one who has looked at this thinks 
this should be done.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/QQ7TBTIQSCXZ66E3WLLT77EUKIQOO3FN/
Code of Conduct: http://python.org/psf/codeofconduct/