[docs] [issue12086] Tutorial doesn't discourage name mangling
Ezio Melotti
report at bugs.python.org
Tue May 17 12:33:46 CEST 2011
Ezio Melotti <ezio.melotti at gmail.com> added the comment:
FWIW that section used to be called "Private variables through name mangling" back in 1.5, and started by saying "There is now limited support for class-private identifiers.".
PEP8 [0] also talks about the name mangling in several places, and carefully avoids the use of "private":
"""
To avoid name clashes with subclasses, use two leading underscores to
invoke Python's name mangling rules.
Python mangles these names with the class name: if class Foo has an
attribute named __a, it cannot be accessed by Foo.__a. (An insistent
user could still gain access by calling Foo._Foo__a.) Generally, double
leading underscores should be used only to avoid name conflicts with
attributes in classes designed to be subclassed.
"""
And it even includes the following two notes:
"""
We don't use the term "private" here, since no attribute is really
private in Python (without a generally unnecessary amount of work).
"""
"""
Not everyone likes name mangling. Try to balance the
need to avoid accidental name clashes with potential use by
advanced callers.
"""
[0]: http://www.python.org/dev/peps/pep-0008/
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12086>
_______________________________________
More information about the docs
mailing list