06.05.21 15:46, Shreyan Avigyan пише: > But Python doesn't have pointers and getattr, settatr can be adjusted to work > with private members.
It doesn't work this way. You cannot distinguish the use of getattr() which breaks encapsulation from the one which does not. Inside getattr() you only have an object, the name of the attribute, and possible fallback value. You don't know whether it was called from the method of that object, in which case the access to private attribute should not be restricted, or outside of it. Changing this would require rewriting significant part of the interpreter code, with possible performance loss, introducing new bugs, and making the maintenance more difficult. There would be needed separate storage for private attributes in object (otherwise you could just access them via __dict__). I am not sure even that the goal is achievable in principle, since in Python there is no hard boundary between methods and functions. You can easily add new methods at runtime. _______________________________________________ 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/Q2B6DEQEN3QG5X3ABKACGANBGUTWWVMP/ Code of Conduct: http://python.org/psf/codeofconduct/