title: Why does the Python's inheritance mechanism allow me to define classes that do not get properly instantiated?
body: <p>I'm sorry for the rather vague formulation of the question. I'll try to clarify what I mean through a simple example below. I have a class I want to use as a base for other classes:</p>
  <pre><code>class parent:
      def __init__(self, constant):
          self.constant = constant
      def addconstant(self, number):
          return self.constant + number
  </code></pre>
  <p>The <code>self.constant</code> parameter is paramount for the usability of the class, as the <code>addconstant</code> method depends on it. Therefore the <code>__init__</code> method takes care of forcing the user to define the value of this parameter. So far so good.</p>
  <p>Now, I define a child class like this:</p>
  <pre><code>class child(parent):
      def __init__(self):
          pass
  </code></pre>
  <p>Nothing stops me from creating an instance of this class, but when I try to use the <code>addconstant</code>, it will obviously crash.</p>
  <pre><code>b = child()
  b.addconstant(5)
  AttributeError: 'child' object has no attribute 'constant'
  </code></pre>
  <p>Why does Python allow to do this!? I feel that Python is &quot;too flexible&quot; and somehow breaks the point of OOP and encapsulation. If I want to extend a class to take advantage of inheritance, I must be careful and know certain details of the implementation of the class. In this case, I have to know that forcing the user to set the <code>constant</code> parameter constant is fundamental not to break the usability of the class. Doesn't this somehow break the encapsulation principle?</p>