]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added code to emit trailing ',' for singleton tuples in two places.
authorGuido van Rossum <guido@python.org>
Sun, 14 Sep 1997 23:21:51 +0000 (23:21 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 14 Sep 1997 23:21:51 +0000 (23:21 +0000)
Lib/pprint.py

index 7f0ab72428ca29dc5885854d863882380130db49..d95cf1a18087323ec513364d23a179f93ed0e351 100644 (file)
@@ -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