import inspect


def super_class_property(*args, **kwargs):
  """
  A class decorator that adds the class' name in lowercase as a property of
  it's superclass with a value constructed using the subclass' constructor with
  the given arguments. So for example:

    class A:
      pass

    @super_class_property(foo=5)
    class B(A):
      def __init__(self, foo=3):
        self.foo=foo

  Effectively results in the following, after the definition of B:

    A.b = B(foo=5)

  Can be used multiple times with different arguments if desired.
  """
  def add_superclass_property(cls):
    nonlocal args, kwargs
    mro = inspect.getmro(cls)
    if len(mro) <= 2:
      raise TypeError(
        (
          "Class {} can't be a super_class_property because it has no super "
          "class."
        ).format(cls)
      )
    parent = mro[1]
    instance = cls(*args, **kwargs)
    setattr(parent, cls.__name__.lower(), instance)
    return cls

  return add_superclass_property