◐ Shell
clean mode source ↗

Message 391590 - Python tracker

I think it gets a little murkier when we talk about *annotations* vs *type hints*.  Type hints have a defined meaning for a string: a string is a sort of forward declaration, and you eval() the string to get the real value.  (Or, not, if you're comfortable working with the stringized version of the type hint.)  So typing.get_type_hints() calls eval() on *every* annotation value of type str.

But inspect.get_annotations() can't be so opinionated.  If the user entered a string as their annotation, it should assume they want the string to show up in the annotations dict.  This is why I'm trying to be so smart with the "eval_str" default value heuristic.

The text in the docs about a "future version of Python" is pursuant to my vague "PEP 1212" idea, which would let get_annotations() determine or not whether the annotations were stringized by the compiler.  Or whatever we wind up deciding to do for Python 3.11--which, as you say, will hopefully disambiguate this question.

p.s. assuming you meant PEP 563, not PEP 573.