Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/stringutil.py @ 39323:ce145f8eface
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
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 22 Aug 2018 11:58:36 -0700 |
parents | 1419ba5e3b56 |
children | 0d21b1f1722c |
comparison
equal
deleted
inserted
replaced
39322:3a60416c4fd8 | 39323:ce145f8eface |
---|---|
11 | 11 |
12 import ast | 12 import ast |
13 import codecs | 13 import codecs |
14 import re as remod | 14 import re as remod |
15 import textwrap | 15 import textwrap |
16 import types | |
16 | 17 |
17 from ..i18n import _ | 18 from ..i18n import _ |
18 from ..thirdparty import attr | 19 from ..thirdparty import attr |
19 | 20 |
20 from .. import ( | 21 from .. import ( |
62 elif isinstance(o, set): | 63 elif isinstance(o, set): |
63 return 'set([%s])' % (b', '.join( | 64 return 'set([%s])' % (b', '.join( |
64 pprint(k, bprefix=bprefix) for k in sorted(o))) | 65 pprint(k, bprefix=bprefix) for k in sorted(o))) |
65 elif isinstance(o, tuple): | 66 elif isinstance(o, tuple): |
66 return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o)) | 67 return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o)) |
68 elif isinstance(o, types.GeneratorType): | |
69 return 'gen[%s]' % (b', '.join(pprint(a, bprefix=bprefix) for a in o)) | |
67 else: | 70 else: |
68 return pycompat.byterepr(o) | 71 return pycompat.byterepr(o) |
69 | 72 |
70 def prettyrepr(o): | 73 def prettyrepr(o): |
71 """Pretty print a representation of a possibly-nested object""" | 74 """Pretty print a representation of a possibly-nested object""" |