This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author larry
Recipients eric.smith, gvanrossum, larry
Date 2021-04-12.17:39:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618249184.39.0.525270769302.issue43817@roundup.psfhosted.org>
In-reply-to
Content
Currently, with PEP 563 looming over us, people who use annotations for something besides type hints are kind of stuck.  Converting stringized annotations back into useful values is a complicated problem, and there's only function in the standard library that will do it for you: typing.get_type_hints().  However, typing.get_type_hints() deals specifically with *type hints*.  Type hints are a subset of annotations, and they have an additional set of rules they want to obey.  As such typing.get_type_hints() is quite opinionated and makes additional changes to the annotations that someone who only wants to un-stringize their annotations likely does not want.

I therefore propose adding a new function to typing:

    typing.get_annotations(o)

This would behave similarly to typing.get_type_hints(o), except it would be agnostic about the contents of the annotations.  It would simply evaluate them, without further changing them as typing.get_type_hints() does.  Specifically:

* It would ignore the "__no_type_check__" attribute.
* It would not wrap string annotations with ForwardRef().
* It would not wrap values with Optional[].
* It would not turn an annotation of None into type(None).
* It would not otherwise change the value of the annotation, in case I missed any.

Since the two functions would be so similar, hopefully either they would share a common implementation, or typing.get_type_hints() could be implemented on top of typing.get_annotations().

Guido, Eric, any thoughts?
History
Date User Action Args
2021-04-12 17:39:44larrysetrecipients: + larry, gvanrossum, eric.smith
2021-04-12 17:39:44larrysetmessageid: <1618249184.39.0.525270769302.issue43817@roundup.psfhosted.org>
2021-04-12 17:39:44larrylinkissue43817 messages
2021-04-12 17:39:44larrycreate