[issue45366] dataclass init=False field with default works but default_factory does not

2021-11-07 Thread Andrei Kulakov
Andrei Kulakov added the comment: I think a good possible solution is to raise an error if `default_factory` is provided on a `init=False` dataclass that doesn't have a `__init__()` defined. However, it will create a slight inconsistency because there will be an error when `__init__` is not

[issue45366] dataclass init=False field with default works but default_factory does not

2021-10-05 Thread Nikita Sobolev
Nikita Sobolev added the comment: Right now `dataclasses.py` has this explanation: https://github.com/python/cpython/blame/07cf10bafc8f6e1fcc82c10d97d3452325fc7c04/Lib/dataclasses.py#L962-L966 ``` if isinstance(getattr(cls, f.name, None), Field): if f.default is MISSING:

[issue45366] dataclass init=False field with default works but default_factory does not

2021-10-04 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue45366] dataclass init=False field with default works but default_factory does not

2021-10-04 Thread simple_coder878
simple_coder878 added the comment: Also wanted to add that I did try another variation of the first example where I set the default_factory field's init value to False and I got the same error. from dataclasses import dataclass, field @dataclass(init=False) class TestObject(object): m: s

[issue45366] dataclass init=False field with default works but default_factory does not

2021-10-04 Thread simple_coder878
New submission from simple_coder878 : Simple example from dataclasses import dataclass, field @dataclass(init=False) class TestObject(object): m: str = field(default='hi') k: list = field(default_factory=list) def test(self): print(f'm is {self.m} ') print(f'k is {s