◐ Shell
clean mode source ↗

Message 391767 - Python tracker

The difference between eval_str=True and eval_str=ONLY_IF_STRINGIZED:

def foo(a:int, b:"howdy howdy"): ...

inspect.get_annotations(foo, eval_str=True) throws an exception.
inspect.get_annotations(foo, eval_str=ONLY_IF_STRINGIZED) returns {'a': int, b: 'howdy howdy'}

Type hints have a convention that string annotations are a "forward declaration" and should be eval()uated.  Annotations don't have such a convention--a string is a legal annotation, and is not required to be valid Python.