Path 1: 795 calls (0.58)

If (714) IfExp (62) Comprehension (19)

Compare (595) Name (133) NamedExpr (46) Attribute (20) IfExp (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 2: 166 calls (0.12)

If (142) Comprehension (20) IfExp (4)

BoolOp (77) UnaryOp (70) Subscript (15) BinOp (4)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 3: 149 calls (0.11)

If (123) Comprehension (14) IfExp (12)

Name (149)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 4: 119 calls (0.09)

If (110) IfExp (7) Comprehension (2)

Const (111) Tuple (2) List (2) GeneratorExp (1) Lambda (1) Dict (1) Set (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 5: 47 calls (0.03)

If (35) IfExp (6) Comprehension (6)

Call (47)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 6: 28 calls (0.02)

If (26) Comprehension (2)

Call (28)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 7: 18 calls (0.01)

If (18)

Name (16) Attribute (2)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 8: 10 calls (0.01)

If (7) Comprehension (2) IfExp (1)

Name (8) Attribute (2)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 9: 8 calls (0.01)

If (8)

Call (8)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 10: 6 calls (0.0)

If (2) IfExp (2) Comprehension (2)

Name (6)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 11: 4 calls (0.0)

Comprehension (4)

Name (4)

InferenceError (4)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 12: 3 calls (0.0)

If (3)

Name (3)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 13: 1 calls (0.0)

If (1)

Attribute (1)

InferenceError (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 14: 1 calls (0.0)

If (1)

Name (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 15: 1 calls (0.0)

If (1)

Call (1)

None (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 16: 1 calls (0.0)

If (1)

Call (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 17: 1 calls (0.0)

If (1)

Name (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
            

Path 18: 1 calls (0.0)

If (1)

Name (1)

None (1)

1def _check_using_constant_test(
2        self,
3        node: nodes.If | nodes.IfExp | nodes.Comprehension,
4        test: nodes.NodeNG | None,
5    ) -> None:
6        const_nodes = (
7            nodes.Module,
8            nodes.GeneratorExp,
9            nodes.Lambda,
10            nodes.FunctionDef,
11            nodes.ClassDef,
12            astroid.bases.Generator,
13            astroid.UnboundMethod,
14            astroid.BoundMethod,
15            nodes.Module,
16        )
17        structs = (nodes.Dict, nodes.Tuple, nodes.Set, nodes.List)
18
19        # These nodes are excepted, since they are not constant
20        # values, requiring a computation to happen.
21        except_nodes = (
22            nodes.Call,
23            nodes.BinOp,
24            nodes.BoolOp,
25            nodes.UnaryOp,
26            nodes.Subscript,
27        )
28        inferred = None
29        emit = isinstance(test, (nodes.Const,) + structs + const_nodes)
30        maybe_generator_call = None
31        if not isinstance(test, except_nodes):
32            inferred = utils.safe_infer(test)
33            if inferred is astroid.Uninferable and isinstance(test, nodes.Name):
34                emit, maybe_generator_call = BasicChecker._name_holds_generator(test)
35
36        # Emit if calling a function that only returns GeneratorExp (always tests True)
37        elif isinstance(test, nodes.Call):
38            maybe_generator_call = test
39        if maybe_generator_call:
40            inferred_call = utils.safe_infer(maybe_generator_call.func)
41            if isinstance(inferred_call, nodes.FunctionDef):
42                # Can't use all(x) or not any(not x) for this condition, because it
43                # will return True for empty generators, which is not what we want.
44                all_returns_were_generator = None
45                for return_node in inferred_call._get_return_nodes_skip_functions():
46                    if not isinstance(return_node.value, nodes.GeneratorExp):
47                        all_returns_were_generator = False
48                        break
49                    all_returns_were_generator = True
50                if all_returns_were_generator:
51                    self.add_message(
52                        "using-constant-test", node=node, confidence=INFERENCE
53                    )
54                    return
55
56        if emit:
57            self.add_message("using-constant-test", node=test, confidence=INFERENCE)
58        elif isinstance(inferred, const_nodes):
59            # If the constant node is a FunctionDef or Lambda then
60            # it may be an illicit function call due to missing parentheses
61            call_inferred = None
62            try:
63                if isinstance(inferred, nodes.FunctionDef):
64                    call_inferred = inferred.infer_call_result()
65                elif isinstance(inferred, nodes.Lambda):
66                    call_inferred = inferred.infer_call_result(node)
67            except astroid.InferenceError:
68                call_inferred = None
69            if call_inferred:
70                try:
71                    for inf_call in call_inferred:
72                        if inf_call != astroid.Uninferable:
73                            self.add_message(
74                                "missing-parentheses-for-call-in-test",
75                                node=test,
76                                confidence=INFERENCE,
77                            )
78                            break
79                except astroid.InferenceError:
80                    pass
81            self.add_message("using-constant-test", node=test, confidence=INFERENCE)