> On Sep 11, 2017, at 4:21 PM, Yury Selivanov <yselivanov...@gmail.com> wrote:
> 
> 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.
> 
> That would maintain full backwards compatibility with all existing
> Python libraries and would not require a future import.

I'm not very thrilled about this because lazy evaluation is subject to the new 
scoping rules (can't use local state) and might give a different result than 
before.  It's not backwards compatible.  A __future__ import makes it obvious 
that behavior is going to be different.

And lazy evaluation is an unnecessary step if `get_type_hints()` is used later 
on so it's unnecessary for the most common usage of annotations.

Finally, I don't think we ever had a "# pragma" suggestion coming from CPython. 
In reality, people wouldn't bother putting it in most files so tools would have 
to assume that forward references are correct *and* avoid raising errors about 
invalid names used in annotations. This is loss of functionality.

- Ł

Attachment: signature.asc
Description: Message signed with OpenPGP

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to