gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / access_to_protected_members.py @ 745
History | View | Annotate | Download (1.17 KB)
1 |
# pylint: disable=too-few-public-methods, W0231, print-statement
|
---|---|
2 |
# pylint: disable=no-classmethod-decorator
|
3 |
"""Test external access to protected class members."""
|
4 |
from __future__ import print_function |
5 |
|
6 |
class MyClass(object): |
7 |
"""Class with protected members."""
|
8 |
_cls_protected = 5
|
9 |
|
10 |
def __init__(self, other): |
11 |
MyClass._cls_protected = 6
|
12 |
self._protected = 1 |
13 |
self.public = other
|
14 |
self.attr = 0 |
15 |
|
16 |
def test(self): |
17 |
"""Docstring."""
|
18 |
self._protected += self._cls_protected |
19 |
print(self.public._haha) # [protected-access] |
20 |
|
21 |
def clsmeth(cls): |
22 |
"""Docstring."""
|
23 |
cls._cls_protected += 1
|
24 |
print(cls._cls_protected) |
25 |
clsmeth = classmethod(clsmeth)
|
26 |
|
27 |
def _private_method(self): |
28 |
"""Doing nothing."""
|
29 |
|
30 |
|
31 |
class Subclass(MyClass): |
32 |
"""Subclass with protected members."""
|
33 |
|
34 |
def __init__(self): |
35 |
MyClass._protected = 5
|
36 |
super(Subclass, self)._private_method() |
37 |
|
38 |
INST = Subclass() |
39 |
INST.attr = 1
|
40 |
print(INST.attr) |
41 |
INST._protected = 2 # [protected-access] |
42 |
print(INST._protected) # [protected-access]
|
43 |
INST._cls_protected = 3 # [protected-access] |
44 |
print(INST._cls_protected) # [protected-access]
|