Issue with accessing annotations as documented in 3.14+

Removing __annotate__ was a change in one of the pre-releases (looking at the date I think the first beta?). It was done to resolve this issue: [3.14] annotationlib - calling `get_annotations` on instances gets an unexpected error · Issue #132261 · python/cpython · GitHub

It has always been the case for 3.14 that the generated annotate functions don’t support Format.STRING or Format.FORWARDREF. I think Format.VALUE_WITH_FAKE_GLOBALS was added in a pre-release and changed the enum values (so you can’t rely on the actual integer values for the enum either).


None of this is to say I’m particularly happy with the state of the current implementation.

In cases where you have to create an __annotate__ function you either have to recreate any logic used to collect the annotations you plan to use within the new annotate function (see this implementation for dataclasses), or you give up and put VALUE or STRING annotations in __annotations__ and assume people already have tooling to deal with string annotations (what I did for my own dataclass-like).

I posted one idea as an attempt to try to improve this situation but there was no interest so I can only assume that needing to generate these is rare, and tools that should be doing so may not have got around to it yet. I know attrs currently just sticks FORWARDREF annotations in __annotations__ which is slightly better than what dataclasses was doing.