[Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft
Ethan Smith
ethan at ethanhs.me
Mon Sep 11 20:33:51 EDT 2017
More information about the Python-ideas mailing list
Mon Sep 11 20:33:51 EDT 2017
- Previous message (by thread): [Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft
- Next message (by thread): [Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Sep 11, 2017 at 1:21 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote: > On Mon, Sep 11, 2017 at 3:25 PM, Lukasz Langa <lukasz at langa.pl> wrote: > [..] > > 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. > > I'm one of those who used annotations for other purposes than type > hints. And even if annotations became strings in Python 3.7 *without > future import*, fixing my libraries would be easy -- just add an > eval(). > > That said, the PEP doesn't cover an alternative solution: > > 1. Add another special attribute to functions: __annotations_text__. > > 2. __annotations__ becomes a dynamic Mapping, which evaluates stuff > from __annotations_text__ *lazily*. > > 3. Recommend linters and IDEs to support "# pragma: annotations", as a > way to say that the Python files follows the new Python 3.7 > annotations semantics. > > I really like this proposal! I agree the linters should understand the semantics of if TYPE_CHECKING, Python 2.7-3.6 will continue to need it. > That would maintain full backwards compatibility with all existing > Python libraries and would not require a future import. > > Yury > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170911/d4c926d5/attachment.html>
- Previous message (by thread): [Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft
- Next message (by thread): [Python-ideas] PEP 563: Postponed Evaluation of Annotations, first draft
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list