members of class not properly shown in workspace with inheritance and usage of __slots__

Issue #191 resolved
M. Gronle created an issue

The following example shows different combinations of inherited classes, where either the base class and / or the inherited class contains members using the __slots__ feature. The workspace does currently not show all slot members from all bases classes. If at least one base class contains the default __dict__ feature, all slots are ignored.

Example:

class WithSlots():
    __slots__ = "a_slot",

    def __init__(self):
        self.a_slot = 7
        #self.x_slot = 0

class WithSlots2(WithSlots):
    __slots__ = ["s2", "s3"]

    def __init__(self):
        self.s2 = -2
        self.s3 = -5
        super(WithSlots2, self).__init__()

class NoSlots():       # This class has __dict__
    def __init__(self):
        self.b_dict = 0

class NoSlots2(NoSlots):
    def __init__(self):
        super(NoSlots2, self).__init__()
        self.c_dict = 6


class A(NoSlots):            # even though A has __slots__, it inherits __dict__
    __slots__ = "a_slot"     # from NoSlots, therefore __slots__ has no effect

    def __init__(self):
        super(A, self).__init__()
        self.a_slot = 9


class B(WithSlots):          # This class has no __dict__
    __slots__ = "some_slot"

    def __init__(self):
        super(B, self).__init__()
        self.some_slot = -1

class C(WithSlots):          # This class has __dict__, because it doesn't
                         # specify __slots__ even though the superclass does.
    def __init__(self):
        super(C, self).__init__()
        self.a_slot = 5
        self.c_dict = 6

x1 = WithSlots()  # ok
x2 = NoSlots() # ok
x3 = A()  # dict of base class wins, slots are not shown
x4 = B()  # slot of base class is missing
x5 = C()  # slot of base class is missing
x6 = WithSlots2()  # slot of base class is missing
x7 = NoSlots2()  # ok

Comments (1)

  1. Log in to comment