title: How to avoid circular imports in class hierarchy located in several files?
body: <p>I want to create instances of several classes at runtime, based on configuration xml files which contain the specific class type and other stuff. Let's start with a simple example:</p>
  <pre><code>class ParentClass:
      @staticmethod
      def create_subclass(class_type: str, xml):
          if class_type == 'childA':
              return ChildClassA(xml)
          elif class_type == 'childB':
              return ChildClassB(xml)
          else:
              return ParentClass(xml)
  
      def __init__(self, xml):
          print('\nParent stuff done.')
  
  
  class ChildClassA(ParentClass):
      def __init__(self, xml):
          super().__init__(xml)
          print('Class A stuff done.')
  
  
  class ChildClassB(ParentClass):
      def __init__(self, xml):
          super().__init__(xml)
          print('Class B stuff done.')
  
  
  ParentClass.create_subclass('childA', None)
  ParentClass.create_subclass('childB', None)
  ParentClass.create_subclass('unknown', None)
  </code></pre>
  <p>The output is as expected:</p>
  <pre><code>Parent stuff done.
  Class A stuff done.
  
  Parent stuff done.
  Class B stuff done.
  
  Parent stuff done.
  </code></pre>
  <p>As the hierarchy grows larger I want to have the parent class in a separate module and each child class in a separate module. Obviously, I need to import the parent module to the child class modules. Due to the <code>create subclass</code> method, the parent class module needs to know about the child classes. Importing those to the parent module would cause a circular import which is considered bad design.</p>
  <p>What would be a good solution to solve this issue? Are there better ways to create the subclass instances?</p>