--- .gitignore
+++ .gitignore
... | ... | @@ -3,3 +3,4 @@ |
3 | 3 |
|
4 | 4 |
## python ## |
5 | 5 |
*.pyc |
6 |
+.scannerwork |
--- python_code/bad/DIP.py
+++ python_code/bad/DIP.py
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 |
class Worker(object): |
5 | 5 |
|
6 | 6 |
def work(self): |
7 |
- print "I'm working!!" |
|
7 |
+ print("I'm working!!") |
|
8 | 8 |
|
9 | 9 |
|
10 | 10 |
class Manager(object): |
... | ... | @@ -13,7 +13,8 @@ |
13 | 13 |
self.worker = None |
14 | 14 |
|
15 | 15 |
def set_worker(self, worker): |
16 |
- assert isinstance(worker, Worker), '`worker` must be of type {}'.format(Worker) |
|
16 |
+ assert isinstance( |
|
17 |
+ worker, Worker), '`worker` must be of type {}'.format(Worker) |
|
17 | 18 |
|
18 | 19 |
self.worker = worker |
19 | 20 |
|
... | ... | @@ -22,15 +23,17 @@ |
22 | 23 |
self.worker.work() |
23 | 24 |
# And some complex codes go here.... |
24 | 25 |
|
26 |
+ |
|
25 | 27 |
class SuperWorker(object): |
26 | 28 |
|
27 | 29 |
def work(self): |
28 |
- print "I work very hard!!!" |
|
30 |
+ print("I work very hard!!!") |
|
29 | 31 |
|
30 | 32 |
# OK... now you can see what happend if we want the `Manager` to support `SuperWorker`. |
31 | 33 |
# 1. The `set_worker` must be modified or it will not pass the type-checking. |
32 |
-# 2. The `manage` method should be re-test, which means you may or may not have to |
|
34 |
+# 2. The `manage` method should be re-test, which means you may or may not have to |
|
33 | 35 |
# rewrite the testing code. |
36 |
+ |
|
34 | 37 |
|
35 | 38 |
def main(): |
36 | 39 |
|
... | ... | @@ -44,7 +47,8 @@ |
44 | 47 |
try: |
45 | 48 |
manager.set_worker(super_worker) |
46 | 49 |
except AssertionError: |
47 |
- print "manager fails to support super_worker...." |
|
50 |
+ print("manager fails to support super_worker....") |
|
51 |
+ |
|
48 | 52 |
|
49 | 53 |
if __name__ == "__main__": |
50 | 54 |
main() |
+++ sonar-project.properties
... | ... | @@ -0,0 +1,5 @@ |
1 | +sonar.projectKey=swlabs:solid | |
2 | +sonar.projectName=solid | |
3 | +sonar.sources=python_code | |
4 | +sonar.language=py | |
5 | +sonar.login=squ_a66b94df1445c77b23cd3fdb266a9ae230e0f8ec |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?