Skip to content

Commit dcc6d9b

Browse files
committed
Worked on articles.
1 parent 97e3b52 commit dcc6d9b

File tree

3 files changed

+36
-87
lines changed

3 files changed

+36
-87
lines changed

docs/correctness/access_to_a_protected_member.rst

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Accessing a protected member from outside the class
2+
===================================================
3+
4+
Summary
5+
-------
6+
7+
Accessing a protected member (a member prefixed with ``_``) of a class from outside that class usually
8+
calls for trouble, since the creator of that class did not intend this function to be exposed.
9+
10+
11+
Example
12+
-------
13+
14+
.. code:: python
15+
16+
class Rectangle(object):
17+
def __init__(self, width, height):
18+
self._width = width
19+
self._height = height
20+
21+
r = Rectangle(5, 6)
22+
print "Width: {:d}".format(r._width) # direct access of protected member
23+
24+
Solutions
25+
---------
26+
27+
If you are absolutely sure that you need to call the proteced function from the outside,
28+
do the following:
29+
* Make sure that calling the function from outside the class does not cause any inadverent side effects.
30+
* Refactor it such that it becomes part of the public interface of the class.
31+
32+
References
33+
----------
34+
35+
- PyLint - W0212

docs/correctness/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.. toctree::
55
:maxdepth: 1
66

7-
access_to_a_protected_member
7+
accessing_a_protected_member_from_outside_the_class
88
bad_except_clauses_order
99
Bad arg for super <bad_first_argument_given_to_super>
1010
Dangerous default arg value <dangerous_default_value_as_argument>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy