@@ -1531,29 +1531,32 @@ def slot_range_as_union(self, slot: SlotDefinition) -> List[ElementName]:
15311531 if x .range :
15321532 range_union_of .append (x .range )
15331533 return range_union_of
1534-
1535- def get_classes_by_slot (self , slot : SlotDefinition , include_induced : bool = False ) -> List [ClassDefinitionName ]:
1534+
1535+ def get_classes_by_slot (
1536+ self , slot : SlotDefinition , include_induced : bool = False
1537+ ) -> List [ClassDefinitionName ]:
15361538 """Get all classes that use a given slot, either as a direct or induced slot.
15371539
15381540 :param slot: slot in consideration
15391541 :param include_induced: supplement all direct slots with induced slots, defaults to False
15401542 :return: list of slots, either direct, or both direct and induced
15411543 """
1542- slots_list = [] # list of all direct or induced slots
1544+ classes_set = set () # use set to avoid duplicates
1545+ all_classes = self .all_classes ()
15431546
1544- for c_name , c in self .all_classes ().items ():
1545- # check if slot is direct specification on class
1547+ for c_name , c in all_classes .items ():
15461548 if slot .name in c .slots :
1547- slots_list . append (c_name )
1549+ classes_set . add (c_name )
15481550
1549- # include induced classes also if requested
15501551 if include_induced :
1551- for c_name , c in self .all_classes ().items ():
1552- for ind_slot in self .class_induced_slots (c_name ):
1553- if ind_slot .name == slot .name :
1554- slots_list .append (c_name )
1555-
1556- return list (dict .fromkeys (slots_list ))
1552+ for c_name in all_classes :
1553+ induced_slot_names = [
1554+ ind_slot .name for ind_slot in self .class_induced_slots (c_name )
1555+ ]
1556+ if slot .name in induced_slot_names :
1557+ classes_set .add (c_name )
1558+
1559+ return list (classes_set )
15571560
15581561 @lru_cache ()
15591562 def get_slots_by_enum (self , enum_name : ENUM_NAME = None ) -> List [SlotDefinition ]:
0 commit comments