Why less emphasis on private data?
Paul Rubin
http
Mon Feb 5 10:54:07 EST 2007
Steve Holden <steve at holdenweb.com> writes:
> >> class A(B):
> >> def bar(self):
> >> self.__x = 5 # clobbers private variable of earlier class named A
> > Has this ever been reported as a bug in Python? I could imagine more
> > sophisticated "name mangling": something to do with the identity of the
> > class might be sufficient, although that would make the tolerated
> > "subversive" access to private attributes rather difficult.
> >
> It would also force the mangling to take place at run-time, which
> would probably affect efficiently pretty adversely (thinks: should
> really check that mangling is a static mechanism before posting this).
I think it could still be done statically. For example, the mangling
could include a random number created at compile time when the class
definition is compiled, that would also get stored in the class object.
I guess there are other ways to create classes than class statements
and those would have to be addressed too.
More information about the Python-list
mailing list