title: python create parent class the function as hashtable
body: <p>i want me class to be used as list, therefor i create Magic class</p>
  <pre><code>@dataclass
  class Magic(Person):
      position = []
  
      def __new__(cls, pos, person):
          if pos &lt; len(cls.position):
              return cls.position[pos]
          if pos == len(cls.position)+1:
              instance = cls.__new__(cls)# should create new class
              cls.position.append(instance)
              return instance
          else:
              raise Exception('out of bound')
  
      def __getitem__(self, pos):
          return self.position[pos]
  </code></pre>
  <p>this class extend Person class, that should contain the content</p>
  <pre><code>@dataclass
  class Person(type):
      age: int = 1
  </code></pre>
  <p>finally I want to fill up the hash</p>
  <pre><code>a = Magic()
  a[0].age = 5
  print(a)
  </code></pre>
  <p>i understand that I should create an instance on the class, but do not understand how
  ahh and i want that the hashtable will be created in order positions
  that i could not create a[1].age =5 before a[0].age =5</p>
  <p>clarify
  While regular lists behave like:</p>
  <pre><code>&gt;&gt;&gt; a = list()
  &gt;&gt;&gt; a[0] = 5
  Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  IndexError: list assignment index out of range
  </code></pre>
  <p>if i write this code the result should be</p>
  <pre><code>&gt;&gt;&gt; a = Magic(Person)
  &gt;&gt;&gt; a[0].age = 5
  &gt;&gt;&gt; print(a)
  [Person(age=5)]
  </code></pre>
  <p>And the list should also enforce its indexes continuity:</p>
  <pre><code>&gt;&gt;&gt; a = Magic(Person)
  &gt;&gt;&gt; a[1].age = 5
  Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 2, in &lt;module&gt;
  IndexError: list index out of range
  </code></pre>