This repository was archived by the owner on Jul 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-7
lines changed
Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -239,11 +239,26 @@ Data Hiding
239239===========
240240
241241Many programming languages has *access modifiers* implemented. The Python has
242- also, but actually no. It's implemented as a convention-level. All class's
243- members starting with underscore are considered to be **protected** members
244- and should not be accessible outside the class instance; on the other hand
245- members starting with two underscores are considered to be **private** members
246- and shouldn't be accessible outside the class instance as well.
242+ also.
243+
244+ .. image:: /../assets/img/wy_ban.jpg
245+ :align: center
246+
247+ "Private" instance variables that cannot be accessed except from inside an
248+ object don't exist in Python :cite:`docs-python:private-variables`. It's
249+ implemented as a convention-level.
250+
251+ A name prefixed with an underscore (e.g. ``_spam``) should be treated as
252+ a non-public part of the API (whether it is a function, a method or a data
253+ member). These should not be used outside the class itself and can be changed
254+ without notice.
255+
256+ Since there is a valid use case for class-private members (namely to avoid name
257+ clashes of names with names defined by subclasses), there is limited support
258+ for such a mechanism, called *name mangling*. Any identifier with at least two
259+ leading underscore (e.g. ``__spam``) is textually replaced with
260+ ``_classname__spam``, where ``_classname`` is the current class name with
261+ leading underscore stripped.
247262
248263.. code-block:: python
249264
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ @misc{docs-python:stdtypes
7373}
7474
7575@misc {docs-python:errors ,
76- title = " {Errors and Exceptions}" ,
76+ title = " {Python Documentation: Errors and Exceptions}" ,
7777 url = { https://docs.python.org/3.11/tutorial/errors.html} ,
78- }
78+ }
79+
80+ @misc {docs-python:private-variables ,
81+ title = " {Python Documentation: Private Variables}" ,
82+ url = { https://docs.python.org/3/tutorial/classes.html?highlight=private#private-variables} ,
83+ }
You can’t perform that action at this time.
0 commit comments