"""
Control write access to class attributes.
Separate data from methods that use it.
Encapsulate class data initialization.
"""


class DataClass:
    """
    Hide all the attributes.
    """

    def __init__(self):
        self.value = None

    def __get__(self, instance, owner):
        return self.value

    def __set__(self, instance, value):
        if self.value is None:
            self.value = value


class MainClass:
    """
    Initialize data class through the data class's constructor.
    """

    attribute = DataClass()

    def __init__(self, value):
        self.attribute = value


def main():
    m = MainClass(True)
    m.attribute = False


if __name__ == "__main__":
    main()

@@ -208,16 +208,23 @@
 t__(self
+, value
 ):%0A     
@@ -230,92 +230,43 @@
     
-self.value = None%0A%0A    def __get__(self, instance, owner):%0A        return self.
+vars(self).update(%7B%22value%22: 
 value
+%7D)
 %0A%0A  
@@ -276,16 +276,20 @@
 ef __set
+attr
 __(self,
@@ -293,15 +293,11 @@
 lf, 
-instanc
+nam
 e, v
@@ -315,61 +315,28 @@
     
-if self.value is None:%0A            self.value = value
+raise AttributeError
 %0A%0A%0Ac
@@ -436,37 +436,8 @@
 %22%22%0A%0A
-    attribute = DataClass()%0A%0A
     
@@ -480,25 +480,32 @@
 elf.
-attribute = 
+_data = DataClass(
 value
+)
 %0A%0A%0Ad
@@ -520,16 +520,17 @@
 ):%0A    m
+2
  = MainC
@@ -538,37 +538,51 @@
 ass(
-True)%0A    m.attribute = False
+%22test%22)%0A    assert m2._data.value == %22test%22
 %0A%0A%0Ai

Improve design