[Python-Dev] Comments on PEP 563 (Postponed Evaluation of Annotations)
lukasz at langa.pl
Mon Nov 20 12:58:02 EST 2017
I agree with you. The special handling of outermost strings vs. strings embedded inside annotations bugged me a lot. Now you convinced me that this functionality should be moved to `get_type_hints()` and the __future__ import shouldn't try to special-case this one instance, while leaving others as is.
I will be amending the PEP accordingly.
> On Nov 19, 2017, at 10:56 AM, Mark Shannon <mark at hotpy.org> wrote:
> Overall I am strongly in favour of this PEP. It pretty much cures all the ongoing pain of using PEP 3017 annotations for type hints.
> There is one thing I don't like however, and that is treating strings as if the quotes weren't there.
> While this seems like a superficial simplification to make transition easier, it introduces inconsistency and will ultimately make both implementing and using type hints harder.
> Having the treatment of strings depend on their depth in the AST seems confusing and unnecessary:
> "List[int]" becomes 'List[int]' # quotes removed
> List["int"] becomes 'List["int"]' # quoted retained
> T = "My unparseable annotation"
> def f()->T: pass
> would remain legal, but
> def f()->"My unparseable annotation"
> would become illegal.
> The change in behaviour between the above two code snippets is already confusing enough without making one of them a SyntaxError.
> Using annotations for purposes other than type hinting is legal and has been for quite a while.
> Also, PEP 484 type-hints are not the only type system in the Python ecosystem. Cython has a long history of using static type hints.
> For tools other than MyPy, the inconsistent quoting is onerous and will require double-quoting to prevent a parse error.
> For example
> def foo()->"unsigned int": ...
> will become illegal and require the cumbersome
> def foo()->'"unsigned int"': ...
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/lukasz%40langa.pl
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 874 bytes
Desc: Message signed with OpenPGP
More information about the Python-Dev