"Private" attributes - a possible idea (maybe PEP-worthy).

Chris Tavares christophertavares at earthlink.net
Sun Feb 3 04:59:59 EST 2002


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1012679645.17201.python-list at python.org...
> [Chris Tavares]
> > How about changing the name mangling rule so that the current
> > number of base classes is added to the secret string?
>
> I'm not sure what "current number of base classes" means.  In
>
> class X(Y):
>     __pvt = 1
>
> what's the current number of base classes?  Keep in mind that
name-mangling
> is done at compile-time, and has only the static text of the module being
> compiled to examine, so the only feasible answer I can come up with is
"1".
> But that wouldn't help (if Y derived from another class named X which
> derived from Z, the count would be 1 on both incarnations of X).
>

Yeah, I see your point. I've been stuck with static languages too long. It
could probably be made to work somehow, but it's not worth the dev effort.

Another idea would be to generate a guid for each class, and use THAT in the
name mangling instead of the counter. That would guarantee uniqueness. Be
kinda hard to manually unmangle, though. Oh, and you'd need a guid generator
on non-windows platforms. But that's a really useful thing to have anyway.
:-)

-Chris






More information about the Python-list mailing list