
On Fri, Nov 26, 2021 at 6:22 PM Abdulla Al Kathiri <alkathiri.abdulla@gmail.com> wrote:
Chris,
Will we able to use late-bound arguments in dataclass when it’s creating the __init__ function?
@dataclass class C: x: int y: int ls: list[int] => [x, y]
With that syntax, no, because there's no object that can be stored in an annotation dictionary that would represent the code construct to create that effect. But the __init__ function is constructed with exec(), and that means that, in theory, dataclasses._field_init could be enhanced to have some way to indicate this - or, possibly, to *always* use late-bound defaults, since it appears to use sentinels for everything. I don't know enough about the workings of dataclasses.dataclass to be able to say for sure, but a cursory glance does suggest that, in some way, this should be possible. It may require stringifying the default though. ls: list[int] = "[x, y]" ChrisA