PEP Idea: Real private attribute

Chris Angelico rosuav at gmail.com
Sun Aug 29 15:56:32 EDT 2021


On Mon, Aug 30, 2021 at 5:49 AM Mehrzad Saremi <mehrzad.1024 at gmail.com> wrote:
>
> No, a class ("the class that I'm lexically inside") cannot be accessed from
> outside of the class. This is why I'm planning to offer it as a core
> feature because only the parser would know. There's apparently no elegant
> solution if you want to implement it yourself. You'll need to write
> self.__privs__[__class__, "foo"], whenever you want to use the feature and
> even wrapping it in superclasses won't remedy it, because the parent class
> isn't aware which class you're inside. It seems to me name mangling must
> have been an ad-hoc solution in a language that it doesn't really fit when
> it could have been implemented in a much more cogent way.
>

If the parent class isn't aware which class you're in, how is the
language going to define it?

Can you give a full run-down of the semantics of your proposed privs,
and how it's different from something like you just used above -
self.__privs__[__class__, "foo"] - ? If the problem is the ugliness
alone, then say so; but also, how this would work with decorators,
since you specifically mention them as a use-case.

ChrisA


More information about the Python-list mailing list