On Wed, Aug 11, 2021 at 10:32 AM Thomas Grainger <tagr...@gmail.com> wrote:
> Larry Hastings wrote: > > On 8/11/21 12:02 AM, Thomas Grainger wrote: > > > I think as long as there's a test case for something like > > > @dataclass > > > class Node: > > > global_node: ClassVar[Node | None] > > > left: InitVar[Node | None] > > > right: InitVar[None | None] > > > > > > the bug https://bugs.python.org/issue33453 and the current > implementation > https://github.com/python/cpython/blob/bfc2d5a5c4550ab3a2fadeb9459b4bd948ff6... > shows this is a tricky problem > > > The most straightforward workaround for this is to skip the decorator > > syntax. With PEP 649 active, this code should work: > > class Node: > > global_node: ClassVar[Node | None] > > left: InitVar[Node | None] > > right: InitVar[None | None] > > Node = dataclass(Node) > > //arry/ > > the decorator version simply has to work > I also think that it would be unfortunate if the decorator version wouldn't work. This is a pretty basic use case. If we go through a lot of trouble to redesign how type annotations behave, it would be great if we could address as many common pain points as possible. Otherwise I see a risk that we'll have another (third!) redesign in Python 3.12 or 3.13. Jukka
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6U27SVAIHIRTFFJVKJWCNIXEJM6YFO6H/ Code of Conduct: http://python.org/psf/codeofconduct/