Path 1: 5524 calls (0.98)

Call (5524)

None (5524)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 2: 73 calls (0.01)

Call (73)

None (73)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 3: 10 calls (0.0)

Call (10)

GeneratorExit (10)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 4: 6 calls (0.0)

Call (6)

GeneratorExit (6)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 5: 5 calls (0.0)

Call (5)

GeneratorExit (2)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 6: 3 calls (0.0)

Call (3)

None (3)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 7: 2 calls (0.0)

Call (2)

None (2)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 8: 2 calls (0.0)

Call (2)

None (2)

NameInferenceError (2)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )
            

Path 9: 1 calls (0.0)

Call (1)

1@utils.only_required_for_messages("use-implicit-booleaness-not-len")
2    def visit_call(self, node: nodes.Call) -> None:
3        # a len(S) call is used inside a test condition
4        # could be if, while, assert or if expression statement
5        # e.g. `if len(S):`
6        if not utils.is_call_of_name(node, "len"):
7            return
8        # the len() call could also be nested together with other
9        # boolean operations, e.g. `if z or len(x):`
10        parent = node.parent
11        while isinstance(parent, nodes.BoolOp):
12            parent = parent.parent
13        # we're finally out of any nested boolean operations so check if
14        # this len() call is part of a test condition
15        if not utils.is_test_condition(node, parent):
16            return
17        len_arg = node.args[0]
18        generator_or_comprehension = (
19            nodes.ListComp,
20            nodes.SetComp,
21            nodes.DictComp,
22            nodes.GeneratorExp,
23        )
24        if isinstance(len_arg, generator_or_comprehension):
25            # The node is a generator or comprehension as in len([x for x in ...])
26            self.add_message(
27                "use-implicit-booleaness-not-len",
28                node=node,
29                confidence=HIGH,
30            )
31            return
32        try:
33            instance = next(len_arg.infer())
34        except astroid.InferenceError:
35            # Probably undefined-variable, abort check
36            return
37        mother_classes = self.base_names_of_instance(instance)
38        affected_by_pep8 = any(
39            t in mother_classes for t in ("str", "tuple", "list", "set")
40        )
41        if "range" in mother_classes or (
42            affected_by_pep8 and not self.instance_has_bool(instance)
43        ):
44            self.add_message(
45                "use-implicit-booleaness-not-len",
46                node=node,
47                confidence=INFERENCE,
48            )