You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dataclass transformation ignores attributes that are annotated as ClassVar. I think it should also ignore attributes that are annotated as TypeAlias.
I think implementing this would add complexity to the code in dataclasses.py (though Eric's the expert!).
For your use case, is it essential that the type alias declaration be inside the class scope? Would it be possible for you to simply have the alias declaration in the global scope instead?
There is of course no hard reason for not using the global scope. I just often have enums (or other types) that are very closely linked to one class. And it makes sense to me then to have a TypeAlias in that class so that I don't have to import the enum separately.
For normal classes, the nested TypeAlias works completely fine in the type checkers I tested (pyright and mypy). It's just dataclasses that are the problem.
But I see now that there is a general wish to keep the implementation of dataclass simple, which I can understand.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: