Path 1: 382 calls (0.75)

AssignAttr (382)

None (382)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 2: 79 calls (0.15)

AssignAttr (79)

None (79)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 3: 15 calls (0.03)

AssignAttr (15)

None (15)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 4: 10 calls (0.02)

AssignAttr (10)

GeneratorExit (10)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 5: 5 calls (0.01)

AssignAttr (5)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 6: 3 calls (0.01)

AssignAttr (3)

None (3)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 7: 3 calls (0.01)

AssignAttr (3)

None (3)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 8: 3 calls (0.01)

AssignAttr (3)

None (3)

GeneratorExit (3)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 9: 2 calls (0.0)

AssignAttr (2)

GeneratorExit (2)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 10: 2 calls (0.0)

AssignAttr (2)

None (2)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 11: 1 calls (0.0)

AssignAttr (1)

None (1)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 12: 1 calls (0.0)

AssignAttr (1)

GeneratorExit (1)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 13: 1 calls (0.0)

AssignAttr (1)

None (1)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 14: 1 calls (0.0)

AssignAttr (1)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 15: 1 calls (0.0)

AssignAttr (1)

GeneratorExit (1)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )
            

Path 16: 1 calls (0.0)

AssignAttr (1)

GeneratorExit (1)

1def _check_in_slots(self, node: nodes.AssignAttr) -> None:
2        """Check that the given AssignAttr node
3        is defined in the class slots.
4        """
5        inferred = safe_infer(node.expr)
6        if not isinstance(inferred, astroid.Instance):
7            return
8
9        klass = inferred._proxied
10        if not has_known_bases(klass):
11            return
12        if "__slots__" not in klass.locals or not klass.newstyle:
13            return
14        # If `__setattr__` is defined on the class, then we can't reason about
15        # what will happen when assigning to an attribute.
16        if any(
17            base.locals.get("__setattr__")
18            for base in klass.mro()
19            if base.qname() != "builtins.object"
20        ):
21            return
22
23        # If 'typing.Generic' is a base of bases of klass, the cached version
24        # of 'slots()' might have been evaluated incorrectly, thus deleted cache entry.
25        if any(base.qname() == "typing.Generic" for base in klass.mro()):
26            cache = getattr(klass, "__cache", None)
27            if cache and cache.get(klass.slots) is not None:
28                del cache[klass.slots]
29
30        slots = klass.slots()
31        if slots is None:
32            return
33        # If any ancestor doesn't use slots, the slots
34        # defined for this class are superfluous.
35        if any(
36            "__slots__" not in ancestor.locals and ancestor.name != "object"
37            for ancestor in klass.ancestors()
38        ):
39            return
40
41        if not any(slot.value == node.attrname for slot in slots):
42            # If we have a '__dict__' in slots, then
43            # assigning any name is valid.
44            if not any(slot.value == "__dict__" for slot in slots):
45                if _is_attribute_property(node.attrname, klass):
46                    # Properties circumvent the slots mechanism,
47                    # so we should not emit a warning for them.
48                    return
49                if node.attrname != "__class__" and utils.is_class_attr(
50                    node.attrname, klass
51                ):
52                    return
53                if node.attrname in klass.locals:
54                    for local_name in klass.locals.get(node.attrname):
55                        statement = local_name.statement(future=True)
56                        if (
57                            isinstance(statement, nodes.AnnAssign)
58                            and not statement.value
59                        ):
60                            return
61                    if _has_data_descriptor(klass, node.attrname):
62                        # Descriptors circumvent the slots mechanism as well.
63                        return
64                if node.attrname == "__class__" and _has_same_layout_slots(
65                    slots, node.parent.value
66                ):
67                    return
68                self.add_message(
69                    "assigning-non-slot",
70                    args=(node.attrname,),
71                    node=node,
72                    confidence=INFERENCE,
73                )