Message404694
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. |
|
Date |
User |
Action |
Args |
2021-10-21 22:31:27 | Thomas701 | set | recipients:
+ Thomas701, eric.smith, Michael Robellard, juanpa.arrivillaga, iivanyuk, UnHumbleBen |
2021-10-21 22:31:27 | Thomas701 | set | messageid: <1634855487.09.0.955655015098.issue39247@roundup.psfhosted.org> |
2021-10-21 22:31:27 | Thomas701 | link | issue39247 messages |
2021-10-21 22:31:27 | Thomas701 | create | |
|