@@ -220,11 +220,15 @@ class Tree:
220220 children: an :term:`iterable` of trees to become the current tree children.
221221 """
222222
223+ __INSTANCE_COUNT = 0
224+
223225 def __init__ (self , root , children = None ):
224226 self .root = root
225227 self .children = list (children ) if children else []
226228 if isinstance (root , Mapping ):
227229 self .attr = AttrDict (root )
230+ Tree .__INSTANCE_COUNT += 1
231+ self .__instance_count = Tree .__INSTANCE_COUNT
228232
229233 def __iter__ (self ):
230234 return iter ([self .root , * self .children ])
@@ -331,14 +335,14 @@ def _gv_graph_(self):
331335 )
332336
333337 def walk (T ):
334- curr = (T .root , T )
338+ curr = (T .root , T . __instance_count )
335339 G .node (curr )
336340 for child in T .children :
337- G .edge (curr , (child .root , child ))
341+ G .edge (curr , (child .root , child . __instance_count ))
338342 if len (T .children ) > 1 :
339343 with G .subgraph (edge_attr = {'style' : 'invis' }, graph_attr = {'rank' : 'same' }) as S :
340344 for f , t in pairwise (T .children ):
341- G .edge ((f .root , f ), (t .root , t ), S )
345+ G .edge ((f .root , f . __instance_count ), (t .root , t . __instance_count ), S )
342346 for child in T .children :
343347 walk (child )
344348
0 commit comments