Method: pylint.checkers.base.comparison_checker.ComparisonChecker._check_literal_comparison
Calls: 106, Exceptions: 0, Paths: 7Back
Path 1: 44 calls (0.42)
Name (21) Call (11) Attribute (5) Compare (4) Tuple (3)
Compare (44)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )
Path 2: 33 calls (0.31)
Const (33)
Compare (33)
None (33)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )
Path 3: 16 calls (0.15)
Const (16)
Compare (16)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )
Path 4: 4 calls (0.04)
List (2) Dict (1) Set (1)
Compare (4)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )
Path 5: 4 calls (0.04)
List (2) Dict (1) Set (1)
Compare (4)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )
Path 6: 3 calls (0.03)
Const (3)
Compare (3)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )
Path 7: 2 calls (0.02)
Const (2)
Compare (2)
1def _check_literal_comparison(
2 self, literal: nodes.NodeNG, node: nodes.Compare
3 ) -> None:
4 """Check if we compare to a literal, which is usually what we do not want to do."""
5 is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
6 is_const = False
7 if isinstance(literal, nodes.Const):
8 if isinstance(literal.value, bool) or literal.value is None:
9 # Not interested in these values.
10 return
11 is_const = isinstance(literal.value, (bytes, str, int, float))
12
13 if is_const or is_other_literal:
14 incorrect_node_str = node.as_string()
15 if "is not" in incorrect_node_str:
16 equal_or_not_equal = "!="
17 is_or_is_not = "is not"
18 else:
19 equal_or_not_equal = "=="
20 is_or_is_not = "is"
21 fixed_node_str = incorrect_node_str.replace(
22 is_or_is_not, equal_or_not_equal
23 )
24 self.add_message(
25 "literal-comparison",
26 args=(
27 incorrect_node_str,
28 equal_or_not_equal,
29 is_or_is_not,
30 fixed_node_str,
31 ),
32 node=node,
33 confidence=HIGH,
34 )