I want to define a decorator (let's name it subcollection) that behaves like this:
class ParentClass:
name = None
def __init__(self, name=None):
self.name = name
@subcollection
class ChildClass:
def greet(self):
print(f'Hello from {self.outter.name}')
parent_class = ParentClass('Mahdi')
child_class = parent_class.ChildClass()
assert child_class.greet() == 'Hello from Mahdi'
I'm trying to achieve a complicated inheritance in python that confused me. This is needed to create a nested unstructured ORM.
I probably could do this with factory functions, but I'm wondering if there is any workaround to pass the parent_class
instance at the time of the child_class
creation with decorators?!