[Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft

Lukasz Langa lukasz at langa.pl
Mon Sep 11 15:25:28 EDT 2017


> On Sep 11, 2017, at 1:16 PM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
> 
> One thing I want to point out: there are a lot of really useful Python
> libraries that have come to rely on annotations being objects, ranging
> from plac to fbuild to many others.

Shout out to fbuild which is a project that was built on Python 3 since early 2008, running on RCs of Python 3.0! Mind=blown.

We are aware of fbuild, plac, and dryparse, Larry Hastings' similar project. But I definitely wouldn't say there are "a lot of" libraries like that, in fact I only know of a handful more, most of them early stage "runtime type checkers" with minimal adoption.

When PEP 484 was put for review, we were testing the waters here, and added wording like:

"In order for maximal compatibility with offline type checking it may eventually be a good idea to change interfaces that rely on annotations to switch to a different mechanism, for example a decorator."

and

"We do hope that type hints will eventually become the sole use for annotations, but this will require additional discussion and a deprecation period after the initial roll-out of the typing module. (...) Another possible outcome would be that type hints will eventually become the default meaning for annotations, but that there will always remain an option to disable them."

Turns out, only authors of a few libraries spoke up AFAICT and most were happy with @no_type_hints. I remember mostly Stefan Behnel's concerns about Cython's annotations, and those never really took off. The bigger uproar at the time was against Python becoming a "statically typed language".

Summing up, PEP 563 is proposing a backwards incompatible change but it doesn't look like it's going to affect "a lot of" libraries. More importantly, it does provide a way for those libraries to keep working.


> I could understand something that
> delays the evaluation of annotations until they are accessed, but this
> seems really extreme.

This PEP is proposing delaying evaluation until annotations are accessed but gives user code the power to decide whether the string form is enough, or maybe an AST would be enough, or actual evaluation with get_type_hints() or eval() is necessary.

- Ł
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170911/18251336/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170911/18251336/attachment-0001.sig>


More information about the Python-ideas mailing list