@@ -512,13 +512,22 @@ class TypePrinter(object):
512
512
def __init__ (self ):
513
513
self .gen = genalnum ()
514
514
self .map = {}
515
+ self .recurse_guard = set ()
515
516
516
517
def name (self , typ ):
517
518
typ = typ .find ()
518
519
if isinstance (typ , TVar ):
519
520
if typ not in self .map :
520
521
self .map [typ ] = "'%s" % next (self .gen )
521
522
return self .map [typ ]
523
+ elif isinstance (typ , TInstance ):
524
+ if typ .name in self .recurse_guard :
525
+ return "<instance {}>" .format (typ .name )
526
+ else :
527
+ self .recurse_guard .add (typ .name )
528
+ attrs = ", " .join (["{}: {}" .format (attr , self .name (typ .attributes [attr ]))
529
+ for attr in typ .attributes ])
530
+ return "<instance {} {{{}}}>" .format (typ .name , attrs )
522
531
elif isinstance (typ , TMono ):
523
532
if typ .params == {}:
524
533
return typ .name
@@ -545,9 +554,13 @@ def name(self, typ):
545
554
elif isinstance (typ , TBuiltinFunction ):
546
555
return "<function {}>" .format (typ .name )
547
556
elif isinstance (typ , (TConstructor , TExceptionConstructor )):
548
- attrs = ", " .join (["{}: {}" .format (attr , self .name (typ .attributes [attr ]))
549
- for attr in typ .attributes ])
550
- return "<constructor {} {{{}}}>" .format (typ .name , attrs )
557
+ if typ .name in self .recurse_guard :
558
+ return "<constructor {}>" .format (typ .name )
559
+ else :
560
+ self .recurse_guard .add (typ .name )
561
+ attrs = ", " .join (["{}: {}" .format (attr , self .name (typ .attributes [attr ]))
562
+ for attr in typ .attributes ])
563
+ return "<constructor {} {{{}}}>" .format (typ .name , attrs )
551
564
elif isinstance (typ , TValue ):
552
565
return repr (typ .value )
553
566
else :
0 commit comments