This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Thomas701
Recipients Michael Robellard, Thomas701, UnHumbleBen, eric.smith, iivanyuk, juanpa.arrivillaga
Date 2021-10-21.22:31:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634855487.09.0.955655015098.issue39247@roundup.psfhosted.org>
In-reply-to
Content
Just to rephrase, because the explanation in my last message can be ambiguous:

At dataclass construction time (when the @dataclass decorator inspects and enhances the class):

for field in fields:
    if descriptor := getattr(field, 'descriptor'):
        setattr(cls, field.name, descriptor)
    elif default := getattr(field, 'default'):
        setattr(cls, field.name, default)


Then at __init__ time:

for field in fields:
    if (
        (descriptor := getattr(field, 'descriptor'))
        and (default := getattr(field, 'default'))
    ):
        setattr(self, field.name, default)
    elif default_factory := getattr(field, 'default_factory'):
        setattr(self, field.name, default_factory())

Now, this is just pseudo-code to illustrate the point, I know the dataclass implementation generates the __init__ on the fly by building its code as a string then exec'ing it. This logic would have to be applied to that generative code.

I keep thinking I'm not seeing some obvious problem here, so if something jumps out let me know.
History
Date User Action Args
2021-10-21 22:31:27Thomas701setrecipients: + Thomas701, eric.smith, Michael Robellard, juanpa.arrivillaga, iivanyuk, UnHumbleBen
2021-10-21 22:31:27Thomas701setmessageid: <1634855487.09.0.955655015098.issue39247@roundup.psfhosted.org>
2021-10-21 22:31:27Thomas701linkissue39247 messages
2021-10-21 22:31:27Thomas701create