Path 1: 3938 calls (0.7)

Call (3938)

None (3938)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 2: 1633 calls (0.29)

Call (1633)

None (1633)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 3: 22 calls (0.0)

Call (22)

NoSuchArgumentError (22)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 4: 10 calls (0.0)

Call (10)

None (10)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 5: 10 calls (0.0)

Call (10)

None (10)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 6: 7 calls (0.0)

Call (7)

NoSuchArgumentError (7)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 7: 2 calls (0.0)

Call (2)

None (2)

NoSuchArgumentError (2)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 8: 2 calls (0.0)

Call (2)

NoSuchArgumentError (2)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 9: 1 calls (0.0)

Call (1)

None (1)

NoSuchArgumentError (1)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))
            

Path 10: 1 calls (0.0)

Call (1)

None (1)

1def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
2        """Add message when accessing first or last elements of a str.split() or
3        str.rsplit().
4        """
5
6        # Check if call is split() or rsplit()
7        if not (
8            isinstance(node.func, nodes.Attribute)
9            and node.func.attrname in {"split", "rsplit"}
10            and isinstance(utils.safe_infer(node.func), astroid.BoundMethod)
11        ):
12            return
13        inferred_expr = utils.safe_infer(node.func.expr)
14        if isinstance(inferred_expr, astroid.Instance) and any(
15            inferred_expr.nodes_of_class(nodes.ClassDef)
16        ):
17            return
18
19        try:
20            sep = utils.get_argument_from_call(node, 0, "sep")
21        except utils.NoSuchArgumentError:
22            return
23
24        try:
25            # Ignore if maxsplit arg has been set
26            utils.get_argument_from_call(node, 1, "maxsplit")
27            return
28        except utils.NoSuchArgumentError:
29            pass
30
31        if isinstance(node.parent, nodes.Subscript):
32            try:
33                subscript_value = utils.get_subscript_const_value(node.parent).value
34            except utils.InferredTypeError:
35                return
36
37            # Check for cases where variable (Name) subscripts may be mutated within a loop
38            if isinstance(node.parent.slice, nodes.Name):
39                # Check if loop present within the scope of the node
40                scope = node.scope()
41                for loop_node in scope.nodes_of_class((nodes.For, nodes.While)):
42                    if not loop_node.parent_of(node):
43                        continue
44
45                    # Check if var is mutated within loop (Assign/AugAssign)
46                    for assignment_node in loop_node.nodes_of_class(nodes.AugAssign):
47                        if node.parent.slice.name == assignment_node.target.name:
48                            return
49                    for assignment_node in loop_node.nodes_of_class(nodes.Assign):
50                        if node.parent.slice.name in [
51                            n.name for n in assignment_node.targets
52                        ]:
53                            return
54
55            if subscript_value in (-1, 0):
56                fn_name = node.func.attrname
57                new_fn = "rsplit" if subscript_value == -1 else "split"
58                new_name = (
59                    node.func.as_string().rsplit(fn_name, maxsplit=1)[0]
60                    + new_fn
61                    + f"({sep.as_string()}, maxsplit=1)[{subscript_value}]"
62                )
63                self.add_message("use-maxsplit-arg", node=node, args=(new_name,))