Method: pylint.checkers.classes.class_checker.ClassChecker._check_redefined_slots
Calls: 50, Exceptions: 0, Paths: 6Back
Path 1: 31 calls (0.62)
ClassDef (31)
List (17) Tuple (13) Dict (1)
list (31)
1def _check_redefined_slots(
2 self,
3 node: nodes.ClassDef,
4 slots_node: nodes.NodeNG,
5 slots_list: list[nodes.NodeNG],
6 ) -> None:
7 """Check if `node` redefines a slot which is defined in an ancestor class."""
8 slots_names: list[str] = []
9 for slot in slots_list:
10 if isinstance(slot, nodes.Const):
11 slots_names.append(slot.value)
12 else:
13 inferred_slot = safe_infer(slot)
14 inferred_slot_value = getattr(inferred_slot, "value", None)
15 if isinstance(inferred_slot_value, str):
16 slots_names.append(inferred_slot_value)
17
18 # Slots of all parent classes
19 ancestors_slots_names = {
20 slot.value
21 for ancestor in node.local_attr_ancestors("__slots__")
22 for slot in ancestor.slots() or []
23 }
24
25 # Slots which are common to `node` and its parent classes
26 redefined_slots = ancestors_slots_names.intersection(slots_names)
27
28 if redefined_slots:
29 self.add_message(
30 "redefined-slots-in-subclass",
31 args=([name for name in slots_names if name in redefined_slots],),
32 node=slots_node,
33 )
Path 2: 11 calls (0.22)
ClassDef (11)
Tuple (8) List (3)
[] (11)
1def _check_redefined_slots(
2 self,
3 node: nodes.ClassDef,
4 slots_node: nodes.NodeNG,
5 slots_list: list[nodes.NodeNG],
6 ) -> None:
7 """Check if `node` redefines a slot which is defined in an ancestor class."""
8 slots_names: list[str] = []
9 for slot in slots_list:
10 if isinstance(slot, nodes.Const):
11 slots_names.append(slot.value)
12 else:
13 inferred_slot = safe_infer(slot)
14 inferred_slot_value = getattr(inferred_slot, "value", None)
15 if isinstance(inferred_slot_value, str):
16 slots_names.append(inferred_slot_value)
17
18 # Slots of all parent classes
19 ancestors_slots_names = {
20 slot.value
21 for ancestor in node.local_attr_ancestors("__slots__")
22 for slot in ancestor.slots() or []
23 }
24
25 # Slots which are common to `node` and its parent classes
26 redefined_slots = ancestors_slots_names.intersection(slots_names)
27
28 if redefined_slots:
29 self.add_message(
30 "redefined-slots-in-subclass",
31 args=([name for name in slots_names if name in redefined_slots],),
32 node=slots_node,
33 )
Path 3: 3 calls (0.06)
ClassDef (3)
Tuple (2) List (1)
list (3)
1def _check_redefined_slots(
2 self,
3 node: nodes.ClassDef,
4 slots_node: nodes.NodeNG,
5 slots_list: list[nodes.NodeNG],
6 ) -> None:
7 """Check if `node` redefines a slot which is defined in an ancestor class."""
8 slots_names: list[str] = []
9 for slot in slots_list:
10 if isinstance(slot, nodes.Const):
11 slots_names.append(slot.value)
12 else:
13 inferred_slot = safe_infer(slot)
14 inferred_slot_value = getattr(inferred_slot, "value", None)
15 if isinstance(inferred_slot_value, str):
16 slots_names.append(inferred_slot_value)
17
18 # Slots of all parent classes
19 ancestors_slots_names = {
20 slot.value
21 for ancestor in node.local_attr_ancestors("__slots__")
22 for slot in ancestor.slots() or []
23 }
24
25 # Slots which are common to `node` and its parent classes
26 redefined_slots = ancestors_slots_names.intersection(slots_names)
27
28 if redefined_slots:
29 self.add_message(
30 "redefined-slots-in-subclass",
31 args=([name for name in slots_names if name in redefined_slots],),
32 node=slots_node,
33 )
Path 4: 3 calls (0.06)
ClassDef (3)
List (3)
list (3)
1def _check_redefined_slots(
2 self,
3 node: nodes.ClassDef,
4 slots_node: nodes.NodeNG,
5 slots_list: list[nodes.NodeNG],
6 ) -> None:
7 """Check if `node` redefines a slot which is defined in an ancestor class."""
8 slots_names: list[str] = []
9 for slot in slots_list:
10 if isinstance(slot, nodes.Const):
11 slots_names.append(slot.value)
12 else:
13 inferred_slot = safe_infer(slot)
14 inferred_slot_value = getattr(inferred_slot, "value", None)
15 if isinstance(inferred_slot_value, str):
16 slots_names.append(inferred_slot_value)
17
18 # Slots of all parent classes
19 ancestors_slots_names = {
20 slot.value
21 for ancestor in node.local_attr_ancestors("__slots__")
22 for slot in ancestor.slots() or []
23 }
24
25 # Slots which are common to `node` and its parent classes
26 redefined_slots = ancestors_slots_names.intersection(slots_names)
27
28 if redefined_slots:
29 self.add_message(
30 "redefined-slots-in-subclass",
31 args=([name for name in slots_names if name in redefined_slots],),
32 node=slots_node,
33 )
Path 5: 1 calls (0.02)
ClassDef (1)
Tuple (1)
list (1)
1def _check_redefined_slots(
2 self,
3 node: nodes.ClassDef,
4 slots_node: nodes.NodeNG,
5 slots_list: list[nodes.NodeNG],
6 ) -> None:
7 """Check if `node` redefines a slot which is defined in an ancestor class."""
8 slots_names: list[str] = []
9 for slot in slots_list:
10 if isinstance(slot, nodes.Const):
11 slots_names.append(slot.value)
12 else:
13 inferred_slot = safe_infer(slot)
14 inferred_slot_value = getattr(inferred_slot, "value", None)
15 if isinstance(inferred_slot_value, str):
16 slots_names.append(inferred_slot_value)
17
18 # Slots of all parent classes
19 ancestors_slots_names = {
20 slot.value
21 for ancestor in node.local_attr_ancestors("__slots__")
22 for slot in ancestor.slots() or []
23 }
24
25 # Slots which are common to `node` and its parent classes
26 redefined_slots = ancestors_slots_names.intersection(slots_names)
27
28 if redefined_slots:
29 self.add_message(
30 "redefined-slots-in-subclass",
31 args=([name for name in slots_names if name in redefined_slots],),
32 node=slots_node,
33 )
Path 6: 1 calls (0.02)
ClassDef (1)
Tuple (1)
list (1)
1def _check_redefined_slots(
2 self,
3 node: nodes.ClassDef,
4 slots_node: nodes.NodeNG,
5 slots_list: list[nodes.NodeNG],
6 ) -> None:
7 """Check if `node` redefines a slot which is defined in an ancestor class."""
8 slots_names: list[str] = []
9 for slot in slots_list:
10 if isinstance(slot, nodes.Const):
11 slots_names.append(slot.value)
12 else:
13 inferred_slot = safe_infer(slot)
14 inferred_slot_value = getattr(inferred_slot, "value", None)
15 if isinstance(inferred_slot_value, str):
16 slots_names.append(inferred_slot_value)
17
18 # Slots of all parent classes
19 ancestors_slots_names = {
20 slot.value
21 for ancestor in node.local_attr_ancestors("__slots__")
22 for slot in ancestor.slots() or []
23 }
24
25 # Slots which are common to `node` and its parent classes
26 redefined_slots = ancestors_slots_names.intersection(slots_names)
27
28 if redefined_slots:
29 self.add_message(
30 "redefined-slots-in-subclass",
31 args=([name for name in slots_names if name in redefined_slots],),
32 node=slots_node,
33 )