def check(self, ndict: dict, info="<STR_LIT>") -> bool:
def iscycle(thing, ndict: dict, info: str) -> bool:<EOL><INDENT>idthing = id(thing)<EOL>ndict[info] = idthing<EOL>if idthing not in ndict:<EOL><INDENT>ndict[idthing] = "<STR_LIT>" % (type(thing), info)<EOL>return False<EOL><DEDENT>else:<EOL><INDENT>ndict[idthing] += "<STR_LIT>" % (type(thing), info)<EOL>return True<EOL><DEDENT><DEDENT>def recurs(thing, ndict: dict, info: str) -> bool:<EOL><INDENT>if not iscycle(thing, ndict, info):<EOL><INDENT>res = False<EOL>if isinstance(thing, list):<EOL><INDENT>idx = <NUM_LIT:0><EOL>for i in thing:<EOL><INDENT>res |= recurs(i, ndict, "<STR_LIT>" % (info, idx))<EOL>idx += <NUM_LIT:1><EOL><DEDENT><DEDENT>elif isinstance(thing, Node):<EOL><INDENT>res |= thing.check(ndict, info)<EOL><DEDENT>elif isinstance(thing, dict):<EOL><INDENT>for k, v in thing.items():<EOL><INDENT>res |= recurs(v, ndict, "<STR_LIT>" % (info, k))<EOL><DEDENT><DEDENT>return res<EOL><DEDENT>return True<EOL><DEDENT>if len(ndict) == <NUM_LIT:0>:<EOL><INDENT>ndict['<STR_LIT>'] = id(self)<EOL>info = '<STR_LIT>'<EOL><DEDENT>if not iscycle(self, ndict, info):<EOL><INDENT>res = False<EOL>if len(self) > <NUM_LIT:0>:<EOL><INDENT>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>keys = list(self.keys())<EOL>for k in keys:<EOL><INDENT>ndict["<STR_LIT:[>" + repr(k) + "<STR_LIT:]>"] = id(self[k])<EOL>res |= recurs(self[k], ndict, "<STR_LIT>" % (info, k))<EOL><DEDENT><DEDENT><DEDENT>keys = list(vars(self).keys())<EOL>for k in keys:<EOL><INDENT>ndict["<STR_LIT:.>" + k] = id(getattr(self, k))<EOL>res |= recurs(getattr(self, k), ndict, "<STR_LIT>" % (info, k))<EOL><DEDENT>return res<EOL><DEDENT>return True<EOL>
Debug method, help detect cycle and/or
other incoherence in a tree of Node