diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-04 10:43:43 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-04 10:43:43 +0200 |
commit | 185ee278f064a3e444a54bf1998d343beb9683a3 (patch) | |
tree | 6acee4c51033467e481bc058e1d25af9fadcaba3 /pylint/test | |
parent | fabcc0526fb1d6b1a876c76f47f54f70d51023c7 (diff) | |
parent | c63ec9cc702161e23db13b3b2397289904073274 (diff) | |
download | pylint-185ee278f064a3e444a54bf1998d343beb9683a3.tar.gz |
Merged in lmedioni/pylint (pull request #298)
check if the number of nested block in a function or a method isn't too high
Diffstat (limited to 'pylint/test')
-rw-r--r-- | pylint/test/functional/too_many_nested_blocks.py | 95 | ||||
-rw-r--r-- | pylint/test/functional/too_many_nested_blocks.txt | 2 |
2 files changed, 97 insertions, 0 deletions
diff --git a/pylint/test/functional/too_many_nested_blocks.py b/pylint/test/functional/too_many_nested_blocks.py new file mode 100644 index 0000000..8d371dd --- /dev/null +++ b/pylint/test/functional/too_many_nested_blocks.py @@ -0,0 +1,95 @@ +"""Checks the maximum block level is smaller than 6 in function definitions""" + +#pylint: disable=using-constant-test, missing-docstring, too-many-return-statements + +def my_function(): + if 1: # [too-many-nested-blocks] + for i in range(10): + if i == 2: + while True: + try: + if True: + i += 1 + except IOError: + pass + + if 1: + for i in range(10): + if i == 2: + while True: + try: + i += 1 + except IOError: + pass + + def nested_func(): + if True: + for i in range(10): + while True: + if True: + if True: + print i + + nested_func() + +def more_complex_function(): + attr1 = attr2 = attr3 = [1, 2, 3] + if attr1: + for i in attr1: + if attr2: + return i + else: + return 'duh' + elif attr2: + for i in attr2: + if attr2: + return i + else: + return 'duh' + else: + for i in range(15): + if attr3: + return i + else: + return 'doh' + return None + +def elif_function(): + arg = None + if arg == 1: + return 1 + elif arg == 2: + return 2 + elif arg == 3: + return 3 + elif arg == 4: + return 4 + elif arg == 5: + return 5 + elif arg == 6: + return 6 + elif arg == 7: + return 7 + +def else_if_function(): + arg = None + if arg == 1: # [too-many-nested-blocks] + return 1 + else: + if arg == 2: + return 2 + else: + if arg == 3: + return 3 + else: + if arg == 4: + return 4 + else: + if arg == 5: + return 5 + else: + if arg == 6: + return 6 + else: + if arg == 7: + return 7 diff --git a/pylint/test/functional/too_many_nested_blocks.txt b/pylint/test/functional/too_many_nested_blocks.txt new file mode 100644 index 0000000..dcee9d2 --- /dev/null +++ b/pylint/test/functional/too_many_nested_blocks.txt @@ -0,0 +1,2 @@ +too-many-nested-blocks:6:my_function:Too many nested blocks (6/5) +too-many-nested-blocks:76:else_if_function:Too many nested blocks (7/5) |