Path 1: 41 calls (0.65)

Compare (41)

'x == 0' (4) 'x != 0' (4) 'k > 1' (3) 'k <= 10' (3) 'x >= 0' (3) 'k != 10' (2) 'current_scope is not None' (2) 'a_var is None' (2) 'a_list is []' (2) ...

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg
            

Path 2: 8 calls (0.13)

Compare (8)

'(a or b) != (c and d)' (2) '(not a) != (not d)' (2) '(a := 10) != (a := 10)' (2) '(a if a == 10 else 0) != (b if b == 10 else 0)' (2)

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg
            

Path 3: 4 calls (0.06)

Name (2) BinOp (2)

'not a_list' (2) 'not x**2' (2)

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg
            

Path 4: 4 calls (0.06)

BoolOp (4)

'not (a and b)' (2) 'not (a and not b)' (2)

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg
            

Path 5: 2 calls (0.03)

UnaryOp (2)

'a_list' (2)

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg
            

Path 6: 2 calls (0.03)

Compare (2)

'(lambda x: x) != k' (2)

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg
            

Path 7: 2 calls (0.03)

Compare (2)

'k != (lambda x: x)' (2)

1def not_condition_as_string(
2    test_node: nodes.Compare | nodes.Name | nodes.UnaryOp | nodes.BoolOp | nodes.BinOp,
3) -> str:
4    msg = f"not {test_node.as_string()}"
5    if isinstance(test_node, nodes.UnaryOp):
6        msg = test_node.operand.as_string()
7    elif isinstance(test_node, nodes.BoolOp):
8        msg = f"not ({test_node.as_string()})"
9    elif isinstance(test_node, nodes.Compare):
10        lhs = test_node.left
11        ops, rhs = test_node.ops[0]
12        lower_priority_expressions = (
13            nodes.Lambda,
14            nodes.UnaryOp,
15            nodes.BoolOp,
16            nodes.IfExp,
17            nodes.NamedExpr,
18        )
19        lhs = (
20            f"({lhs.as_string()})"
21            if isinstance(lhs, lower_priority_expressions)
22            else lhs.as_string()
23        )
24        rhs = (
25            f"({rhs.as_string()})"
26            if isinstance(rhs, lower_priority_expressions)
27            else rhs.as_string()
28        )
29        msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}"
30    return msg