[Jython-checkins] jython: Fixes #2672 by applying github PR #102 by James Mudd with minor edits.
stefan.richthofer
jython-checkins at python.org
Mon Jul 9 09:13:11 EDT 2018
https://hg.python.org/jython/rev/123a2956db3f
changeset: 8168:123a2956db3f
user: James Mudd <james.mudd at gmail.com>
date: Mon Jul 09 15:12:49 2018 +0200
summary:
Fixes #2672 by applying github PR #102 by James Mudd with minor edits.
files:
Lib/test/test_format_jy.py | 25 ++++++++++
Lib/test/test_list_jy.py | 2 +-
NEWS | 3 +-
src/org/python/core/stringlib/IntegerFormatter.java | 5 +-
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_format_jy.py b/Lib/test/test_format_jy.py
--- a/Lib/test/test_format_jy.py
+++ b/Lib/test/test_format_jy.py
@@ -22,6 +22,29 @@
def __float__(self): return self. x
self.assertEqual('1.0', '%.1f' % Foo(1.0))
+ def test_formatting_int_min_value_as_decimal(self):
+ # Test for http://bugs.jython.org/issue2672
+ x = int(-(1<<31))
+ self.assertEqual('-2147483648', '%d' % x)
+ self.assertEqual('-2147483648', '%i' % x)
+
+ def test_formatting_int_min_value_as_hex(self):
+ # Test for http://bugs.jython.org/issue2672
+ x = int(-(1<<31))
+ self.assertEqual('-80000000', '%x' % x)
+ self.assertEqual('-80000000', '%X' % x)
+
+ def test_formatting_int_min_value_as_octal(self):
+ # Test for http://bugs.jython.org/issue2672
+ x = int(-(1<<31))
+ self.assertEqual('-20000000000', '%o' % x)
+
+ def test_formatting_int_min_value_as_binary(self):
+ # Test for http://bugs.jython.org/issue2672
+ x = int(-(1<<31))
+ self.assertEqual('-10000000000000000000000000000000', '{0:b}'.format(x))
+
+
class FormatUnicodeBase(unittest.TestCase):
# Test padding non-BMP result
@@ -29,6 +52,7 @@
self.padcheck(u"architect")
self.padcheck(u'a\U00010001cde')
+
class FormatUnicodeClassic(FormatUnicodeBase):
# Check using %-formatting
@@ -39,6 +63,7 @@
self.assertEqual(u' '*6 + s[0:4], '%010.4s' % s)
self.assertEqual(s[0:3] + u' '*5, '%-8.3s' % s)
+
class FormatUnicodeModern(FormatUnicodeBase):
# Check using __format__
diff --git a/Lib/test/test_list_jy.py b/Lib/test/test_list_jy.py
--- a/Lib/test/test_list_jy.py
+++ b/Lib/test/test_list_jy.py
@@ -257,7 +257,7 @@
self.assertEqual(jl, b_to_z_by_2)
def test_concat(self):
- # See http://bugs.jython.org/issue2688
+ # See http://bugs.jython.org/issue2688
lst = ArrayList([1, 2, 3])
lst2 = [4, 5, 6]
self.assertEquals(lst+lst2, [1, 2, 3, 4, 5, 6])
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -2,8 +2,9 @@
For more details, please see https://hg.python.org/jython
-Developement tip
+Development tip
Bugs fixed
+ - [ 2672 ] Integer formatting emits two minus signs with -2^31
- [ 2688 ] ClassCastException when adding list of non-PyObjects
- [ 2659 ] Determine console encoding without access violation (Java 9)
- [ 2662 ] IllegalAccessException accessing public abstract method via PyReflectedFunction
diff --git a/src/org/python/core/stringlib/IntegerFormatter.java b/src/org/python/core/stringlib/IntegerFormatter.java
--- a/src/org/python/core/stringlib/IntegerFormatter.java
+++ b/src/org/python/core/stringlib/IntegerFormatter.java
@@ -327,7 +327,10 @@
if (value < 0) {
// Negative value: deal with sign and base, and convert magnitude.
negativeSign(null);
- number = Integer.toString(-value);
+ // Here there is a special case for int min value due to wrapping, to avoid a double
+ // negative sign being added see http://bugs.jython.org/issue2672
+ // The string constant here is -Integer.MIN_VALUE
+ number = value == Integer.MIN_VALUE ? "2147483648" : Integer.toString(-value);
} else {
// Positive value: deal with sign, base and magnitude.
positiveSign(null);
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list