Created
May 2, 2020 02:57
-
-
Save aynik/56f9869c883e13da44e1a6dc1ec3a5d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FieldRoot(object): | |
def __init__(self, __id__, __parent_repr__=lambda x: x): | |
self.__id__ = __id__ | |
self.__parent_repr__ = __parent_repr__ | |
def __repr__(self): | |
return self.__parent_repr__(self.__id__) | |
def __embed__(self, child, __id__): | |
return child(__id__, | |
__parent_repr__=lambda x: self.__parent_repr__( | |
self.__id__ + '{' + x + '}')) | |
class B(FieldRoot): | |
@property | |
def a(self): | |
return self.__embed__(A, 'a') | |
class A(FieldRoot): | |
@property | |
def b(self): | |
return self.__embed__(B, 'b') | |
a = A('a') | |
# a.b.a.b.a.b.a.b = 'a{b{a{b{a{b{a{b}}}}}}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment