[Python-Dev] Re: PEP 649: Deferred Evaluation Of Annotations Using Descriptors, round 2

2021年4月13日 18:46:46 -0700

On 4/13/21 1:52 PM, Guido van Rossum wrote:
On Tue, Apr 13, 2021 at 12:32 PM Larry Hastings <[email protected] <mailto:[email protected]>> wrote:
 On 4/12/21 7:24 PM, Guido van Rossum wrote:
 I've been thinking about this a bit, and I think that the way
 forward is for Python to ignore the text of annotations ("relaxed
 annotation syntax"), not to try and make it available as an
 expression.
 To be honest, the most pressing issue with annotations is the
 clumsy way that type variables have to be introduced. The current
 convention, `T = TypeVar('T')`, is both verbose (why do I have to
 repeat the name?) and widely misunderstood (many help request for
 mypy and pyright follow from users making a mistaken association
 between two type variables that are unrelated but share the same
 TypeVar definition). And relaxed annotation syntax alone doesn't
 solve this.
 Nevertheless I think that it's time to accept that annotations
 are for types -- the intention of PEP 3107 was to experiment with
 different syntax and semantics for types, and that experiment has
 resulted in the successful adoption of a specific syntax for
 types that is wildly successful.
 I don't follow your reasoning. I'm glad that type hints have
 found success, but I don't see why that implies "and therefore we
 should restrict the use of annotations solely for type hints". 
 Annotations are a useful, general-purpose feature of Python, with
 legitimate uses besides type hints. Why would it make Python
 better to restrict their use now?
Because typing is, to many folks, a Really Important Concept, and it's confusing to use the same syntax ("x: blah blah") for different purposes, in a way that makes it hard to tell whether a particular "blah blah" is meant as a type or as something else -- because you have to know what's introspecting the annotations before you can tell. And that introspection could be signalled by a magical decorator, but it could also be implicit: maybe you have a driver that calls a function based on a CLI entry point name, and introspects that function even if it's not decorated.
I'm not sure I understand your point. Are you saying that we need to take away the general-purpose functionality of annotations, that's been in the language since 3.0, and restrict annotations to just type hints... because otherwise an annotation might not be used for a type hint, and then the programmer would have to figure out what it means? We need to take away the functionality from all other use cases in order to lend /clarity/ to one use case? Also, if you're stating that programmers get confused reading source code because annotations get used for different things at different places--surely that confirms that annotations are /useful/ for more than just type hints, in real-world code, today. I genuinely have no sense of how important static type analysis is in Python--personally I have no need for it--but I find it hard to believe that type hints are so overwhelmingly important that they should become the sole use case for annotations, and we need to take away this long-standing functionality, that you suggest is being successfully used side-by-side with type hints today, merely to make type hints clearer.
Cheers,
//arry/
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/6QIYSBQPXA3IU7MJL6XQAU6U3RPWSNA7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to