[Python-Dev] Re: Proto-PEP part 4: The wonderful third option

2022年5月01日 15:11:42 -0700

On 5/1/22 15:44, Paul Bryan wrote:
Can someone state what's currently unpalatable about 649? It seemed to address the forward-referencing issues, certainly all of the cases I was expecting to encounter.
Carl's talk was excellent here; it would be lovely if he would chime in and reply. Here is my almost-certainly-faulty recollection of what he said.
 * PEP 649 doesn't work for code bases that deliberately using
 un-evaluatable expressions but still examine them at runtime. Some
 code bases would have a major circular import problem if they had to
 import every module they use in annotations. By only importing
 those in "if TYPE_CHECKING" blocks, mypy (which inspects each module
 in isolation) can resolve the references, so it works fine at static
 analysis time. Occasionally they /also/ need to examine the
 annotation at runtime, but this is only a rudimentary check, so a
 string works fine for them. So 563 works, but 649 throws e.g. a
 NameError. Carl proposes a mitigation strategy here: run the
 co_annotations code object with a special globals dict set that
 creates fake objects instead of failing on lookups.
 * PEP 649 is a pain point for libraries using annotations for
 documentation purposes. The annotation as written may be very
 readable, but evaluating it may turn into a very complicated object,
 and the repr() or str() of that object may be a complicated and
 obscure the original intent. Carl proposes using much the same
 strategy here; also it /might/ work to use ast.unparse to pull the
 original expression out of the source code, though this seems like
 it would be less reliable.
That's everything I remember... but I was operating on two hours' sleep that day. You might also consult Brett's thread about finding edge cases in PEPs 484, 563, and 649:
 
https://discuss.python.org/t/finding-edge-cases-for-peps-484-563-and-649-type-annotations/14314/18
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/YGX4URVSXRNGPFROCHEQ4Q5HRYVIZ22S/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to