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

Scott David Daniels Scott.Daniels at Acm.Org
Mon Dec 12 18:34:26 CET 2005


Jeremy Hylton wrote:
> On 12/12/05, Scott David Daniels <Scott.Daniels at acm.org> wrote:
>> Perhaps "The __ name convention is designed for 'mixins'; as a means of
>> enforcing "private" it is both ineffective and annoying.  For example,
>> distutils.msvccompiler uses a bunch of instance variables which would I
>> would like to access in a subclass, but are "unavailable" because the
>> author could not imagine why I would need them.
> 
> These are really separate issues, right?  The effect of __ names is to
> make a variable private to a class, because it's a right pain to
> access it from any other class.  If you design a class for inheritance
> and use __ names, you're deciding to keep the details of those names
> private.
For 'mixins' (or other multi-inheritance schemes) the renaming serves a
useful (and necessary) function -- collision avoidance.

In a hierarchy designed for inheritance, I suspect fewer problems than I
see in the cited code.  For code built with no thought of inheritance,
it will be easier to (re) use parts if non-'__' names are used.  Code
built for inheritance is not responsible for the correctness of
subclasses; I suspect many '__' names are used in a mistaken attempt
to prevent subclasses from making mistakes, rather than attempting
to ease their use.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-Dev mailing list