On Thu, Oct 21, 2021 at 1:08 PM Henry Fredrick Schreiner
<henry.fredrick.schrei...@cern.ch> wrote:
>
> > typing features from future Python versions
>
> I second both of these uses, but especially this (which seems to be missing 
> from the original post), it’s been by far the main reason I’ve used this mode 
> and I’ve seen this used, and is the main feature to look forward to when 
> dropping Python 3.7 support. The new features coming to typing make static 
> typing much easier, but no libraries can drop Python 3.7/3.8/3.9 support; but 
> static typing doesn’t need old versions.
>

I agree with this point. We shouldn't emit DeprecationWarning for
`from __future__ import annotations` at least 3 versions (3.11 ~
3.13).

> When talking about speed, one of the important things to consider here is the 
> difference between the two proposals. PEP 649 was about the same as the 
> current performance, but PEP 563 was significantly faster, since it doesn’t 
> instantiate or deal with objects at all, which both the current default and 
> PEP 563 do. You could even protect imports with TYPE_CHECKING with PEP 563, 
> and further reduce the runtime cost of adding types - which could be seen as 
> a reason to avoid adding types. To the best of my knowledge, it hasn’t been a 
> blocker for packages, but something to include.
>
> Also, one of the original points for static typing is that strings can be 
> substituted for objects. “Type” is identical, from a static typing 
> perspective, to Type. You can swap one for the other, and for a Python 3.6+ 
> codebase, using something like “A | B” (with the quotes) is a valid way to 
> have static types in 3.6 that pass MyPy (though are not usable at runtime, 
> obviously, but that’s often not a requirement). NumPy, for example, makes 
> heavy usage of unions and other newer additions in static typing.
>

We may be able to provide tool to rewrite Python sources like 2to3:

* Remove `from __future__ import annotations`
* Stringify annotations, if it is not constants (e.g. `None`, `42`,
`"foo"` are not rewrote).

This tool can ease transition from PEP 563 to 649, and solve
performance issues too.
PEP 649 can have the performance as PEP 563 if all annotations are constants.

-- 
Inada Naoki  <songofaca...@gmail.com>
_______________________________________________
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/ZFGRO6UGFVOBPTW2EFNLUC7WEYPCRLAQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to