Returns a list of all slots of a class and its parents. Args: obj (:obj:`type`): The class or class-instance to get the slots from. only_parents (:obj:`bool`, optional): If ``True``, only the slots of the parents are returned. Defaults to ``False``.
(obj, only_parents: bool = False)
| 20 | |
| 21 | |
| 22 | def mro_slots(obj, only_parents: bool = False): |
| 23 | """Returns a list of all slots of a class and its parents. |
| 24 | Args: |
| 25 | obj (:obj:`type`): The class or class-instance to get the slots from. |
| 26 | only_parents (:obj:`bool`, optional): If ``True``, only the slots of the parents are |
| 27 | returned. Defaults to ``False``. |
| 28 | """ |
| 29 | cls = obj if inspect.isclass(obj) else obj.__class__ |
| 30 | |
| 31 | classes = cls.__mro__[1:] if only_parents else cls.__mro__ |
| 32 | |
| 33 | return [ |
| 34 | attr |
| 35 | for cls in classes |
| 36 | if hasattr(cls, "__slots__") # The Exception class doesn't have slots |
| 37 | for attr in cls.__slots__ |
| 38 | ] |
no outgoing calls
searching dependent graphs…