title: Avoid class variable in python subclass when parent class requires to declare it
body: <p>I read that it is considered bad practice to create a variable in the class namespace and then change its value in the class constructor.</p>
  
  <p>(One of my sources: <a href="https://softwareengineering.stackexchange.com/questions/254576/is-it-a-good-practice-to-declare-instance-variables-as-none-in-a-class-in-python">SoftwareEngineering SE: Is it a good practice to declare instance variables as None in a class in Python</a>.)</p>
  
  <p>Consider the following code:</p>
  
  <pre><code># lib.py
  class mixin:
      def __init_subclass__(cls, **kwargs):
          cls.check_mixin_subclass_validity(cls)
          super().__init_subclass__(**kwargs)
  
      def check_mixin_subclass_validity(subclass):
          assert hasattr(subclass, 'necessary_var'), \
              'Missing necessary_var'
  
      def method_used_by_subclass(self):
          return self.necessary_var * 3.14
  
  
  # app.py
  class my_subclass(mixin):
      necessary_var = None
  
      def __init__(self, some_value):
          self.necessary_var = some_value
  
      def run(self):
          # DO SOME STUFF
          self.necessary_var = self.method_used_by_subclass()
          # DO OTHER STUFF
  </code></pre>
  
  <p>To force its subclass to declare the variable <em>necessary_var</em>, the class <code>mixin</code> uses the metaclass <code>subclass_validator</code>.</p>
  
  <p>And the only way I know to makes it work on <strong><code>app.py</code></strong> side, is to initialized <em>necessary_var</em> as a class variable.</p>
  
  <p><strong>I am missing something or is it the only way to do so?</strong></p>