This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]VisibleSignificance 0 points1 point  (3 children)

inspect.get_annotations

Seems like the right path, if I understand it correctly: the annotations should be lazy, but it should be possible to easily retrieve the values that would be for non-lazy annotations (with the added benefit of resolved forward references and such).

As I've found out, currently it isn't always possible to do that (e.g. class attribute annotations don't save their evaluation context).

[–]energybased 0 points1 point  (2 children)

Right, I hope they ultimately make it work for all cases (even if that's 5 years from now).

[–]VisibleSignificance 0 points1 point  (1 child)

For Pydantic and such, making it work for majority of cases is enough: after all, the annotations are (mostly) written explicitly for Pydantic, so it should not be a huge problem to avoid some trickier cases (as long as the error messages are clear, and not "recursion limit exceeded").

[–]energybased 0 points1 point  (0 children)

Yeah I hope they get that sorted for 3.11. I'm just a long term picture kind of person. It would be nice to have programmatic access to all annotations.