Path 1: 43 calls (0.41)

Call (43)

[] (43)

{} (42) dict (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 2: 15 calls (0.14)

Call (15)

list (15)

dict (15)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 3: 7 calls (0.07)

Call (7)

list (7)

dict (7)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 4: 6 calls (0.06)

Call (6)

list (6)

{} (5) dict (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 5: 5 calls (0.05)

Call (5)

list (5)

{} (5)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 6: 4 calls (0.04)

Call (4)

list (4)

dict (4)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 7: 2 calls (0.02)

Call (2)

list (2)

{} (2)

NoSuchArgumentError (2)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 8: 2 calls (0.02)

Call (2)

list (2)

dict (2)

AstroidIndexError (1) AstroidTypeError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 9: 2 calls (0.02)

Call (2)

list (2)

{} (2)

AstroidIndexError (1) AstroidTypeError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 10: 2 calls (0.02)

Call (2)

list (2)

{} (2)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 11: 2 calls (0.02)

Call (2)

list (2)

{} (2)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 12: 2 calls (0.02)

Call (2)

list (2)

{} (2)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 13: 2 calls (0.02)

Call (2)

list (2)

dict (2)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 14: 1 calls (0.01)

Call (1)

list (1)

{} (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 15: 1 calls (0.01)

Call (1)

list (1)

dict (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 16: 1 calls (0.01)

Call (1)

list (1)

dict (1)

AttributeInferenceError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 17: 1 calls (0.01)

Call (1)

list (1)

dict (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 18: 1 calls (0.01)

Call (1)

list (1)

dict (1)

AttributeInferenceError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 19: 1 calls (0.01)

Call (1)

list (1)

dict (1)

AstroidTypeError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 20: 1 calls (0.01)

Call (1)

list (1)

{} (1)

AttributeInferenceError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 21: 1 calls (0.01)

Call (1)

list (1)

dict (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 22: 1 calls (0.01)

Call (1)

list (1)

dict (1)

AttributeInferenceError (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break
            

Path 23: 1 calls (0.01)

Call (1)

list (1)

{} (1)

1def _check_new_format_specifiers(
2        self,
3        node: nodes.Call,
4        fields: list[tuple[str, list[tuple[bool, str]]]],
5        named: dict[str, SuccessfulInferenceResult],
6    ) -> None:
7        """Check attribute and index access in the format
8        string ("{0.a}" and "{0[a]}").
9        """
10        key: Literal[0] | str
11        for key, specifiers in fields:
12            # Obtain the argument. If it can't be obtained
13            # or inferred, skip this check.
14            if not key:
15                # {[0]} will have an unnamed argument, defaulting
16                # to 0. It will not be present in `named`, so use the value
17                # 0 for it.
18                key = 0
19            if isinstance(key, int):
20                try:
21                    argname = utils.get_argument_from_call(node, key)
22                except utils.NoSuchArgumentError:
23                    continue
24            else:
25                if key not in named:
26                    continue
27                argname = named[key]
28            if argname in (astroid.Uninferable, None):
29                continue
30            try:
31                argument = utils.safe_infer(argname)
32            except astroid.InferenceError:
33                continue
34            if not specifiers or not argument:
35                # No need to check this key if it doesn't
36                # use attribute / item access
37                continue
38            if argument.parent and isinstance(argument.parent, nodes.Arguments):
39                # Ignore any object coming from an argument,
40                # because we can't infer its value properly.
41                continue
42            previous = argument
43            parsed: list[tuple[bool, str]] = []
44            for is_attribute, specifier in specifiers:
45                if previous is astroid.Uninferable:
46                    break
47                parsed.append((is_attribute, specifier))
48                if is_attribute:
49                    try:
50                        previous = previous.getattr(specifier)[0]
51                    except astroid.NotFoundError:
52                        if (
53                            hasattr(previous, "has_dynamic_getattr")
54                            and previous.has_dynamic_getattr()
55                        ):
56                            # Don't warn if the object has a custom __getattr__
57                            break
58                        path = get_access_path(key, parsed)
59                        self.add_message(
60                            "missing-format-attribute",
61                            args=(specifier, path),
62                            node=node,
63                        )
64                        break
65                else:
66                    warn_error = False
67                    if hasattr(previous, "getitem"):
68                        try:
69                            previous = previous.getitem(nodes.Const(specifier))
70                        except (
71                            astroid.AstroidIndexError,
72                            astroid.AstroidTypeError,
73                            astroid.AttributeInferenceError,
74                        ):
75                            warn_error = True
76                        except astroid.InferenceError:
77                            break
78                        if previous is astroid.Uninferable:
79                            break
80                    else:
81                        try:
82                            # Lookup __getitem__ in the current node,
83                            # but skip further checks, because we can't
84                            # retrieve the looked object
85                            previous.getattr("__getitem__")
86                            break
87                        except astroid.NotFoundError:
88                            warn_error = True
89                    if warn_error:
90                        path = get_access_path(key, parsed)
91                        self.add_message(
92                            "invalid-format-index", args=(specifier, path), node=node
93                        )
94                        break
95
96                try:
97                    previous = next(previous.infer())
98                except astroid.InferenceError:
99                    # can't check further if we can't infer it
100                    break