Method: pylint.checkers.utils.is_augmented_assign
Calls: 658, Exceptions: 0, Paths: 10Back
Path 1: 604 calls (0.92)
Assign (604)
(False, '') (604)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 2: 21 calls (0.03)
Assign (21)
(True, '+') (6) (True, '%') (4) (True, '|') (2) (True, '-') (1) (True, '*') (1) (True, '/') (1) (True, '//') (1) (True, '<<') (1) (True, '>>') (1) (Tr...
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 3: 9 calls (0.01)
Assign (9)
(True, '+') (5) (True, '*') (1) (True, '^') (1) (True, '&') (1) (True, '|') (1)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 4: 7 calls (0.01)
Assign (7)
(False, '') (7)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 5: 5 calls (0.01)
Assign (5)
(False, '') (5)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 6: 4 calls (0.01)
Assign (4)
(False, '') (4)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 7: 3 calls (0.0)
Assign (3)
(False, '') (3)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 8: 3 calls (0.0)
Assign (3)
(False, '') (3)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 9: 1 calls (0.0)
Assign (1)
(False, '') (1)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""
Path 10: 1 calls (0.0)
Assign (1)
(False, '') (1)
1def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]:
2 """Determine if the node is assigning itself (with modifications) to itself.
3
4 For example: x = 1 + x
5 """
6 if not isinstance(node.value, nodes.BinOp):
7 return False, ""
8
9 binop = node.value
10 target = node.targets[0]
11
12 if not isinstance(target, (nodes.AssignName, nodes.AssignAttr)):
13 return False, ""
14
15 # We don't want to catch x = "1" + x or x = "%s" % x
16 if isinstance(binop.left, nodes.Const) and isinstance(
17 binop.left.value, (str, bytes)
18 ):
19 return False, ""
20
21 # This could probably be improved but for now we disregard all assignments from calls
22 if isinstance(binop.left, nodes.Call) or isinstance(binop.right, nodes.Call):
23 return False, ""
24
25 if _is_target_name_in_binop_side(target, binop.left):
26 return True, binop.op
27 if (
28 # Unless an operator is commutative, we should not raise (i.e. x = 3/x)
29 binop.op in COMMUTATIVE_OPERATORS
30 and _is_target_name_in_binop_side(target, binop.right)
31 ):
32 inferred_left = safe_infer(binop.left)
33 if isinstance(inferred_left, nodes.Const) and isinstance(
34 inferred_left.value, int
35 ):
36 return True, binop.op
37 return False, ""
38 return False, ""