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.

too_many_nested_blocks.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """Checks the maximum block level is smaller than 6 in function definitions"""
  2. #pylint: disable=using-constant-test, missing-docstring, too-many-return-statements,no-else-return
  3. def my_function():
  4. if 1: # [too-many-nested-blocks]
  5. for i in range(10):
  6. if i == 2:
  7. while True:
  8. try:
  9. if True:
  10. i += 1
  11. except IOError:
  12. pass
  13. if 1:
  14. for i in range(10):
  15. if i == 2:
  16. while True:
  17. try:
  18. i += 1
  19. except IOError:
  20. pass
  21. def nested_func():
  22. if True:
  23. for i in range(10):
  24. while True:
  25. if True:
  26. if True:
  27. yield i
  28. nested_func()
  29. def more_complex_function():
  30. attr1 = attr2 = attr3 = [1, 2, 3]
  31. if attr1:
  32. for i in attr1:
  33. if attr2:
  34. return i
  35. else:
  36. return 'duh'
  37. elif attr2:
  38. for i in attr2:
  39. if attr2:
  40. return i
  41. else:
  42. return 'duh'
  43. else:
  44. for i in range(15):
  45. if attr3:
  46. return i
  47. else:
  48. return 'doh'
  49. return None
  50. def elif_function():
  51. arg = None
  52. if arg == 1:
  53. return 1
  54. elif arg == 2:
  55. return 2
  56. elif arg == 3:
  57. return 3
  58. elif arg == 4:
  59. return 4
  60. elif arg == 5:
  61. return 5
  62. elif arg == 6:
  63. return 6
  64. elif arg == 7:
  65. return 7
  66. return None
  67. def else_if_function():
  68. arg = None
  69. if arg == 1: # [too-many-nested-blocks]
  70. return 1
  71. else:
  72. if arg == 2:
  73. return 2
  74. else:
  75. if arg == 3:
  76. return 3
  77. else:
  78. if arg == 4:
  79. return 4
  80. else:
  81. if arg == 5:
  82. return 5
  83. else:
  84. if arg == 6:
  85. return 6
  86. else:
  87. if arg == 7:
  88. return 7
  89. return None