Path 1: 1212 calls (0.8)

ClassDef (1212)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 2: 162 calls (0.11)

ClassDef (162)

GeneratorExit (162)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 3: 49 calls (0.03)

ClassDef (49)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 4: 46 calls (0.03)

ClassDef (46)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 5: 20 calls (0.01)

ClassDef (20)

None (20)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 6: 11 calls (0.01)

ClassDef (11)

AttributeInferenceError (11)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 7: 3 calls (0.0)

ClassDef (3)

AttributeInferenceError (3)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 8: 3 calls (0.0)

ClassDef (3)

GeneratorExit (3)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 9: 3 calls (0.0)

ClassDef (3)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 10: 2 calls (0.0)

ClassDef (2)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 11: 2 calls (0.0)

ClassDef (2)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 12: 1 calls (0.0)

ClassDef (1)

AttributeInferenceError (1)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 13: 1 calls (0.0)

ClassDef (1)

AttributeInferenceError (1)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 14: 1 calls (0.0)

ClassDef (1)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 15: 1 calls (0.0)

ClassDef (1)

AttributeInferenceError (1)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 16: 1 calls (0.0)

ClassDef (1)

AttributeInferenceError (1)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )
            

Path 17: 1 calls (0.0)

ClassDef (1)

GeneratorExit (1)

1def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
2        # check access to existent members on non metaclass classes
3        if (
4            "attribute-defined-outside-init"
5            in self.linter.config.ignored_checks_for_mixins
6            and self._mixin_class_rgx.match(cnode.name)
7        ):
8            # We are in a mixin class. No need to try to figure out if
9            # something is missing, since it is most likely that it will
10            # miss.
11            return
12
13        accessed = self._accessed.accessed(cnode)
14        if cnode.type != "metaclass":
15            self._check_accessed_members(cnode, accessed)
16        # checks attributes are defined in an allowed method such as __init__
17        if not self.linter.is_message_enabled("attribute-defined-outside-init"):
18            return
19        defining_methods = self.linter.config.defining_attr_methods
20        current_module = cnode.root()
21        for attr, nodes_lst in cnode.instance_attrs.items():
22            # Exclude `__dict__` as it is already defined.
23            if attr == "__dict__":
24                continue
25
26            # Skip nodes which are not in the current module and it may screw up
27            # the output, while it's not worth it
28            nodes_lst = [
29                n
30                for n in nodes_lst
31                if not isinstance(
32                    n.statement(future=True), (nodes.Delete, nodes.AugAssign)
33                )
34                and n.root() is current_module
35            ]
36            if not nodes_lst:
37                continue  # error detected by typechecking
38
39            # Check if any method attr is defined in is a defining method
40            # or if we have the attribute defined in a setter.
41            frames = (node.frame(future=True) for node in nodes_lst)
42            if any(
43                frame.name in defining_methods or is_property_setter(frame)
44                for frame in frames
45            ):
46                continue
47
48            # check attribute is defined in a parent's __init__
49            for parent in cnode.instance_attr_ancestors(attr):
50                attr_defined = False
51                # check if any parent method attr is defined in is a defining method
52                for node in parent.instance_attrs[attr]:
53                    if node.frame(future=True).name in defining_methods:
54                        attr_defined = True
55                if attr_defined:
56                    # we're done :)
57                    break
58            else:
59                # check attribute is defined as a class attribute
60                try:
61                    cnode.local_attr(attr)
62                except astroid.NotFoundError:
63                    for node in nodes_lst:
64                        if node.frame(future=True).name not in defining_methods:
65                            # If the attribute was set by a call in any
66                            # of the defining methods, then don't emit
67                            # the warning.
68                            if _called_in_methods(
69                                node.frame(future=True), cnode, defining_methods
70                            ):
71                                continue
72                            self.add_message(
73                                "attribute-defined-outside-init", args=attr, node=node
74                            )