@@ -293,12 +293,24 @@ def _to_tree(ast_node):
293
293
294
294
return _to_tree (node )
295
295
296
+ def to_lol (self ):
297
+ def walk (T ):
298
+ return (T .root , * tuple (walk (child ) for child in T .children ))
299
+
300
+ return walk (self )
301
+
296
302
def __repr__ (self ):
297
303
def walk (T ):
298
304
return '({}: {})' .format (T .root , ', ' .join (map (walk , T .children ))) if T .children else f'({ T .root } )'
299
305
300
306
return walk (self )
301
307
308
+ def __eq__ (self , other ):
309
+ return isinstance (other , Tree ) and self .to_lol () == other .to_lol ()
310
+
311
+ def __hash__ (self ):
312
+ return hash (self .to_lol ())
313
+
302
314
def _gv_graph_ (self ):
303
315
G = GVWrapper (
304
316
dict ( # noqa: C408
@@ -712,7 +724,8 @@ def _fmt(r, c):
712
724
letstr (self .data [r ], self .fmt ['elem_sep' ], sort = self .fmt ['letstr_sort' ], remove_outer = True ),
713
725
)
714
726
for r in rows
715
- ), True
727
+ ),
728
+ True ,
716
729
)
717
730
718
731
@@ -735,7 +748,8 @@ def _repr_html_(self):
735
748
)
736
749
+ '</pre></td>'
737
750
for l in range (N , L - 1 , - 1 ) # noqa: E741
738
- ), True
751
+ ),
752
+ True ,
739
753
)
740
754
741
755
@@ -777,8 +791,13 @@ def embed_css(custom_css=CUSTOM_CSS):
777
791
return HTML (f'<style>{ custom_css } </style>' )
778
792
779
793
780
- def liblet_table (content , as_str = False ):
781
- return f'<table class="liblet" data-quarto-disable-processing="true">{ content } </table>' if as_str else HTML (f'<table class=liblet>{ content } </table>' )
794
+ def liblet_table (content , as_str = False ):
795
+ return (
796
+ f'<table class="liblet" data-quarto-disable-processing="true">{ content } </table>'
797
+ if as_str
798
+ else HTML (f'<table class=liblet>{ content } </table>' )
799
+ )
800
+
782
801
783
802
def resized_svg_repr (obj , width = 800 , height = 600 ):
784
803
if hasattr (obj , '_repr_image_svg_xml' ):
0 commit comments