stringutil: teach pprint() to recognize generators
authorGregory Szorc <gregory.szorc@gmail.com>
Wed, 22 Aug 2018 11:58:36 -0700
changeset 39296 ce145f8eface
parent 39295 3a60416c4fd8
child 39297 06c976acc581
stringutil: teach pprint() to recognize generators Otherwise they get serialized as e.g. <generator object X at 0x7f543d3d68c0> Differential Revision: https://phab.mercurial-scm.org/D4396
mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py	Mon Aug 27 16:03:00 2018 -0400
+++ b/mercurial/utils/stringutil.py	Wed Aug 22 11:58:36 2018 -0700
@@ -13,6 +13,7 @@
 import codecs
 import re as remod
 import textwrap
+import types
 
 from ..i18n import _
 from ..thirdparty import attr
@@ -64,6 +65,8 @@
             pprint(k, bprefix=bprefix) for k in sorted(o)))
     elif isinstance(o, tuple):
         return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o))
+    elif isinstance(o, types.GeneratorType):
+        return 'gen[%s]' % (b', '.join(pprint(a, bprefix=bprefix) for a in o))
     else:
         return pycompat.byterepr(o)