[issue43817] Add inspect.get_annotations()

Jelle Zijlstra report at bugs.python.org
Mon Apr 26 17:43:27 EDT 2021


Jelle Zijlstra <jelle.zijlstra at gmail.com> added the comment:

I agree with Guido that it's better to design inspect.signature to not throw an error for annotations that don't eval() cleanly.

I use inspect.signature for getting information about callables (third-party and first-party) in my type checker: https://github.com/quora/pyanalyze/blob/master/pyanalyze/arg_spec.py#L436. 
 In that context, I'd much rather get string annotations that I can process myself later than get an exception if the annotations aren't valid at runtime. In the former case I can still get useful information out of the signature even if I don't know how to process some annotations. For example, I'll still know what parameters exist even if I don't know what their types are. In the latter case, I don't get any useful signature data.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43817>
_______________________________________


More information about the Python-bugs-list mailing list