[Python-Dev] Deprecate __ private (was Re: PEP 8 updates/clarifications)

Adam Olsen rhamph at gmail.com
Tue Dec 13 14:14:19 CET 2005


On 12/12/05, Guido van Rossum <guido at python.org> wrote:
> Unfortunately that fails one of the other requirements, which (at the
> time of implementation) was minimal impact on the rest of the
> interpreter. Since __private isn't limited to self, and attribute
> lookup doesn't always result in a dict lookup, this would require a
> complete overhaul of the getattr API, both at the C and at the Python
> level.

I hate to flog a dead horse but I feel it's important to clarify my
intentions here.  I don't see why it couldn't require a dict. 
Immutable builtins will fail either way, and so will classes using
slots (unless they hardcode the required private name).  The only
problematic use-case I can think of is a proxy class, but is that
enough to dictate the entire design of the feature?

> But I guess you already said that when you said """Obviously it
> doesn't handle backwards compatibility, so it's more of a "if I could
> do it again.." suggestion."""

I was referring to code which already hardcodes the format of the
current approach, i.e.:
class Foo(object):
    def __init__(self):
        self.__private = 42
f = Foo()
print f._Foo__private

--
Adam Olsen, aka Rhamphoryncus


More information about the Python-Dev mailing list