[Python-checkins] cpython: Issue #22824: Simplify reprlib output format for empty arrays
raymond.hettinger
python-checkins at python.org
Sat Nov 15 19:59:07 CET 2014
https://hg.python.org/cpython/rev/cf5b910ac4c8
changeset: 93497:cf5b910ac4c8
user: Raymond Hettinger <python at rcn.com>
date: Sat Nov 15 10:58:58 2014 -0800
summary:
Issue #22824: Simplify reprlib output format for empty arrays
files:
Lib/reprlib.py | 2 ++
Lib/test/test_reprlib.py | 2 +-
Misc/NEWS | 3 +++
3 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/Lib/reprlib.py b/Lib/reprlib.py
--- a/Lib/reprlib.py
+++ b/Lib/reprlib.py
@@ -83,6 +83,8 @@
return self._repr_iterable(x, level, '[', ']', self.maxlist)
def repr_array(self, x, level):
+ if not x:
+ return "array('%s')" % x.typecode
header = "array('%s', [" % x.typecode
return self._repr_iterable(x, level, header, '])', self.maxarray)
diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py
--- a/Lib/test/test_reprlib.py
+++ b/Lib/test/test_reprlib.py
@@ -94,7 +94,7 @@
eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}")
# array.array after 5.
- eq(r(array('i')), "array('i', [])")
+ eq(r(array('i')), "array('i')")
eq(r(array('i', [1])), "array('i', [1])")
eq(r(array('i', [1, 2])), "array('i', [1, 2])")
eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -209,6 +209,9 @@
- Issue #22824: Updated reprlib output format for sets to use set literals.
Patch contributed by Berker Peksag.
+- Issue #22824: Updated reprlib output format for arrays to display empty
+ arrays without an unnecessary empty list. Suggested by Serhiy Storchaka.
+
- Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
Based on patch by Martin Panter.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list