On 2021-05-06 12:46:40, Shreyan Avigyan wrote: > But Python doesn't have pointers and getattr, settatr can be adjusted > to work with private members.
Not really, this is explicitly mentioned on the docs. Here's an example: > >>> from dataclasses import dataclass > >>> @dataclass(frozen=True) > ... class Example: > ... field: str > ... > >>> e1 = Example('string') > >>> e1.field > 'string' > >>> e1.field = 'Something' > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<string>", line 4, in __setattr__ > dataclasses.FrozenInstanceError: cannot assign to field 'field' > >>> e1.__setattr__('field', 'Something') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<string>", line 4, in __setattr__ > dataclasses.FrozenInstanceError: cannot assign to field 'field' > >>> object.__setattr__(e1, 'field', 'Something') > >>> e1.field > 'Something' "private" member are just a convention, always. No reflection or pointer manipulation is necessary to change them, let alone just reading. "@property", "getattr"/"setattr", "@cached_property" solves all problems that Java introduces with worthless getters and setters. _______________________________________________ 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/7X2DFPJIBJG4POPETFPKXVPI536XGORP/ Code of Conduct: http://python.org/psf/codeofconduct/