summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-09-14 23:21:51 (GMT)
committerGuido van Rossum <guido@python.org>1997-09-14 23:21:51 (GMT)
commita1dbe50ec27da4d2e8f1bb6266fe158846476552 (patch)
tree07f8830d15ff43ff22266d58318d9d860174c529
parent83551bfeda04311f54a19c0e069faea21d8f73bd (diff)
downloadcpython-a1dbe50ec27da4d2e8f1bb6266fe158846476552.zip
cpython-a1dbe50ec27da4d2e8f1bb6266fe158846476552.tar.gz
cpython-a1dbe50ec27da4d2e8f1bb6266fe158846476552.tar.bz2
Added code to emit trailing ',' for singleton tuples in two places.
-rw-r--r--Lib/pprint.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py
index 7f0ab72..d95cf1a 100644
--- a/Lib/pprint.py
+++ b/Lib/pprint.py
@@ -147,6 +147,8 @@ class PrettyPrinter:
self.__format(ent, stream, indent,
allowance + 1, context, level)
indent = indent - self.__indent_per_level
+ if typ is TupleType and length == 1:
+ stream.write(',')
stream.write(((typ is ListType) and ']') or ')')
elif sepLines and typ is DictType:
@@ -226,7 +228,11 @@ def _safe_repr(object, context, maxlevels=None, level=0):
object[0], context, maxlevels, level)
readable = readable and subreadable
s = s + subrepr
- for ent in object[1:]:
+ tail = object[1:]
+ if not tail:
+ if typ is TupleType:
+ s = s + ','
+ for ent in tail:
subrepr, subreadable = _safe_repr(
ent, context, maxlevels, level)
readable = readable and subreadable