Dexter Hill wrote: > Do you mind providing a little example of what you mean? I'm not sure I 100% > understand what your use of `__post_init__` is. In my mind, it would be > something like: > ```py > @dataclass > class Foo: > x: str = field(init=int, converter=chr) > # which converts to > class Foo: > def __init__(self, x: int): > self.x = chr(x) > ``` > without any use of `__post_init__`. If it were to be something like: > ```py > class Foo: > def __init__(self, x: int): > self.__post_init__(x) > def __post_init__(x: int): > self.x = chr(x) > ``` > which, I think is what you are suggesting (please correct me if I'm wrong), > then I feel that may be confusing if you were to override `__post_init__`, > which is often much easier than overriding `__init__`. > For exmple, in a situation like: > ```py > @dataclass > class Foo: > x: str = field(init=int, converter=chr) > y: InitVar[str] > ``` > if the user were to override `__post_init__`, would they know that they need > to include `x` as the first argument? It's not typed with `InitVar` so it > might not be clear that it's passed to `__post_init__`. That's close to what I mean. I'm actually suggesting to not have 'converter though, and instead use an explicit `__post_init__` for that, so ```py @dataclass class Foo: x: str = field(init=int)
def __post_init__(self, x: int): self.x = chr(x) # converts to class Foo: def __init__(self, x: int): self.__post_init__(x) def __post_init__(self, x: int): self.x = chr(x) ``` Writing that out is helpful because now I see that the argument type can possibly be taken from the `__post_init__` signature, meaning there is no need to use the type as the value for the `init` argument to `field`. In that case, instead of `init=int`, it could maybe be something like `post_init=True`. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/LI7ZSAZ6VGQV4OEP7ZOXIWIKA4VLMWXJ/ Code of Conduct: http://python.org/psf/codeofconduct/