| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
This should be ready now; I think this approach is the least invasive and most maintainable: we strip annotations when we find them and otherwise adjust the regex to ignore them in leading position. The annotation stripping could be factored out to another function if we wanted. |
Sorry, something went wrong.
|
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: 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. |
Sorry, something went wrong.
|
@ericvsmith Because my PR removing the need for passing callable() was merged (#31151), I've removed the __call__ method from this PR. |
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
|
Hi @JelleZijlstra I'm triaging stale PRs and came across this one. I just tested the issue against main and it still reproduces, so the fix is still relevant. The diff looks reasonable to me. Snippet to reproducePython 3.15.0a8+ (heads/main:f4a726da402, Jun 8 2026, 12:51:26) [Clang 17.0.0 (clang-1700.0.13.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from dataclasses import dataclass, fields >>> from typing import ClassVar, Annotated >>> >>> @dataclass ... class A: ... x: int ... y: ClassVar[int] = 0 ... >>> @dataclass ... class B: ... x: int ... y: Annotated[ClassVar[int], "meta"] = 0 ... >>> print([f.name for f in fields(A)]) ['x'] >>> print([f.name for f in fields(B)]) ['x', 'y'] Since this was approved a while back but never merged, would you still feel comfortable with the changes if main was merged back in? I'm also happy to help get it over the line, if that's useful. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
We also remove the support for leading spaces in stringified dataclasses annotations (ref https://bugs.python.org/issue46552 ) and allow nested leading Annotated[] annotations (see the PEP).