gh-90669: Let typing.Annotated wrap dataclasses annotations by GBeauregard · Pull Request #30997 · python/cpython
This code is ready for review, but I'll mention another option if you're interested:
The code currently allows anything with a symbol named Annotated on the regex side of things, as we discussed in the bpo issue. I see a way we can support renaming the Annotated symbols within a single regex as long as all nested Annotated symbols are renamed the same way, and then we would inspect the dict to get names similar to how you do for ClassVar. The downside is it complicates the regex processing part of the code a good bit and the regex becomes a lot more opaque. Here was a prototype I was playing with for context:
^(?P<lead>(?:(?P<frontmod>\w+)\s*\.\s*)?(?P<frontsym>\w+)\s*\[\s*)?(?P=lead)*(?:(?P<backmod>\w+)\s*\.)?\s*(?P<backsym>\w+)
An even better approach is using a new regex to nibble at matches at the front of the string annotation and check one by one if they are Annotated until you reach one that isn't. This should be able to support everything.
This is a lot more complicated so I don't intend to introduce it unless you see this as important.