Larry Hastings <la...@hastings.org> added the comment:
I keep thinking about it, and I think letting inspect.get_annotations() and inspect.signature() raise exceptions is the right API choice. I note that that's what typing.get_type_hints() did in Python 3.9. During the development of Python 3.10, this was changed; typing.get_type_hints() started catching Exception and returning the original annotation dictionary (with un-eval'd strings). This change has been reverted, and as of the current moment typing.get_type_hints() no longer catches exceptions on eval(). I think there are two types of people who will have string annotations that throw an exception when eval'd: 1) People who made a typo or other mistake. 2) People who deliberately use undefined identifiers in their annotations, due to circular import / circular dependencies in their code bases. The people who are saying "just catch the exception and let it pass silently" seem to be in group 2. I suggest that people in group 2 are sophisticated enough to start passing in eval_str=False to inspect.signature(). And I think people in group 1 would want to be alerted to their mistake, rather than have the library silently catch the error and mysteriously change its behavior. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43817> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com