
In this case PEP 649 doesn't help.
Sorry for the naive question but why doesn't PEP 649 help here? Is there something fundamental about the dataclass that needs to inspect the type of C.a to create the dataclass? - Damian (he/him) On Tue, Aug 10, 2021 at 1:10 PM Łukasz Langa <lukasz@langa.pl> wrote:
On 10 Aug 2021, at 13:05, Eric V. Smith <eric@trueblade.com> wrote:
If 649 is accepted, there will be few places where stringified annotations will be needed. For example, forward references that are defined before __annotations__ is examined will not need to be specified as strings. From the PEP: "Actually, annotations would become much easier to use, as they would now also handle forward references.
In general, yes, agreed. However, a popular special case that you're intimately familiar with are class decorators. Since those are executed quite eagerly, you'll have to account for failing evaluation of forward references. Example:
from dataclasses import dataclass
@dataclass class C: a: A
class A: ...
In this case PEP 649 doesn't help. I don't see evaluation failures discussed explicitly in the PEP but I assume it would be a NameError. It would also be interesting to see if we can somehow make it handle annotations that refer to the class they're used in. Example:
@dataclass class Node: parent: Node
- Ł _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/FVJAUJ4T... Code of Conduct: http://python.org/psf/codeofconduct/