Message391919
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. |
|
Date |
User |
Action |
Args |
2021-04-26 13:08:40 | larry | set | recipients:
+ larry, gvanrossum, barry, eric.smith, methane, lukasz.langa, JelleZijlstra, xtreak, kj |
2021-04-26 13:08:40 | larry | set | messageid: <1619442520.56.0.380966980112.issue43817@roundup.psfhosted.org> |
2021-04-26 13:08:40 | larry | link | issue43817 messages |
2021-04-26 13:08:39 | larry | create | |
|