Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mccabe.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. """Checks use of "too-complex" check"""
  2. def f1():
  3. """McCabe rating: 1"""
  4. pass
  5. def f2(n):
  6. """McCabe rating: 1"""
  7. k = n + 4
  8. s = k + n
  9. return s
  10. def f3(n):
  11. """McCabe rating: 3"""
  12. if n > 3:
  13. return "bigger than three"
  14. elif n > 4:
  15. return "is never executed"
  16. else:
  17. return "smaller than or equal to three"
  18. def f4():
  19. """McCabe rating: 2"""
  20. for i in range(10):
  21. print(i)
  22. def f5(mylist):
  23. """McCabe rating: 2"""
  24. for i in mylist:
  25. print(i)
  26. else:
  27. print(None)
  28. def f6(n):
  29. """McCabe rating: 2"""
  30. if n > 4:
  31. return f(n - 1)
  32. else:
  33. return n
  34. def f7():
  35. """McCabe rating: 3"""
  36. def b():
  37. """McCabe rating: 2"""
  38. def c():
  39. """McCabe rating: 1"""
  40. pass
  41. c()
  42. b()
  43. def f8():
  44. """McCabe rating: 4"""
  45. try:
  46. print(1)
  47. except TypeA:
  48. print(2)
  49. except TypeB:
  50. print(3)
  51. else:
  52. print(4)
  53. def f9():
  54. """McCabe rating: 9"""
  55. myint = 2
  56. if myint > 5:
  57. pass
  58. else:
  59. if myint <= 5:
  60. pass
  61. else:
  62. myint = 3
  63. if myint > 2:
  64. if myint > 3:
  65. pass
  66. elif myint == 3:
  67. pass
  68. elif myint < 3:
  69. pass
  70. else:
  71. if myint:
  72. pass
  73. else:
  74. if myint:
  75. pass
  76. myint = 4
  77. def f10():
  78. """McCabe rating: 11"""
  79. myint = 2
  80. if myint == 5:
  81. return myint
  82. elif myint == 6:
  83. return myint
  84. elif myint == 7:
  85. return myint
  86. elif myint == 8:
  87. return myint
  88. elif myint == 9:
  89. return myint
  90. elif myint == 10:
  91. if myint == 8:
  92. while True:
  93. return True
  94. elif myint == 8:
  95. with myint:
  96. return 8
  97. else:
  98. if myint == 2:
  99. return myint
  100. return myint
  101. return myint
  102. class MyClass1(object):
  103. """Class of example to test mccabe"""
  104. _name = 'MyClass' # To force a tail.node=None
  105. def method1():
  106. """McCabe rating: 1"""
  107. pass
  108. def method2(self, param1):
  109. """McCabe rating: 18"""
  110. if not param1:
  111. pass
  112. pass
  113. if param1:
  114. pass
  115. else:
  116. pass
  117. pass
  118. if param1:
  119. pass
  120. if param1:
  121. pass
  122. if param1:
  123. pass
  124. if param1:
  125. pass
  126. if param1:
  127. pass
  128. if param1:
  129. pass
  130. if param1:
  131. for value in range(5):
  132. pass
  133. pass
  134. for count in range(6):
  135. with open('myfile') as fp:
  136. count += 1
  137. pass
  138. pass
  139. try:
  140. pass
  141. if not param1:
  142. pass
  143. else:
  144. pass
  145. if param1:
  146. raise BaseException('Error')
  147. with open('myfile2') as fp2:
  148. pass
  149. pass
  150. finally:
  151. if param1 is not None:
  152. pass
  153. for count2 in range(8):
  154. try:
  155. pass
  156. except BaseException('Error2'):
  157. pass
  158. return param1
  159. for count in range(10):
  160. if count == 1:
  161. exit(0)
  162. elif count == 2:
  163. exit(1)
  164. else:
  165. exit(2)
  166. def method3(self):
  167. try:
  168. if True:
  169. pass
  170. else:
  171. pass
  172. finally:
  173. pass
  174. return True