Message391225
> Hey Larry, it would seem that PEP 649 as currently specified would make it impossible to access annotations via the inspect module in cases where x.__annotations__ raises (because one of the annotations references an undefined variable).
That's true. If PEP 649 is accepted, inspect.signature() might want to catch NameError when examining __annotations__ on the object. Though I'm not sure what it should do when the exception is raised.
> I really think that we need *some* way of accessing partial annotations. Even just leaving the failing key out of __annotations__ (but keeping other keys if their annotation works) would be better than failing to return an __annotations__ dict at all.
Unfortunately I don't agree--"errors should never pass silently." Silently omitting the failed annotation seems like it would be a bad experience. What if the value you needed from the annotation was the one that was omitted? Now you have a mystery obscuring your existing problem.
There is a PR against PEP 649 specifically to suppress NameErrors:
https://github.com/larryhastings/co_annotations/pull/3
I haven't merged the PR as I don't agree with it. |
|
Date |
User |
Action |
Args |
2021-04-16 16:20:23 | larry | set | recipients:
+ larry, gvanrossum, eric.smith, The Compiler, levkivskyi, kj |
2021-04-16 16:20:23 | larry | set | messageid: <1618590023.82.0.656456922038.issue43463@roundup.psfhosted.org> |
2021-04-16 16:20:23 | larry | link | issue43463 messages |
2021-04-16 16:20:23 | larry | create | |
|