diff options
author | Eric Smith <eric@trueblade.com> | 2009-05-05 14:04:18 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2009-05-05 14:04:18 (GMT) |
commit | 63376228a3f2d3ac4a21a10c0653c3b984c2d686 (patch) | |
tree | e781a7c8a1abe5c032d83bbc2948c4bd34d4d77e /Lib | |
parent | 86a05ecdb5eb91cf174e9b3c8adf0187e868aa68 (diff) | |
download | cpython-63376228a3f2d3ac4a21a10c0653c3b984c2d686.zip cpython-63376228a3f2d3ac4a21a10c0653c3b984c2d686.tar.gz cpython-63376228a3f2d3ac4a21a10c0653c3b984c2d686.tar.bz2 |
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_complex.py | 10 | ||||
-rw-r--r-- | Lib/test/test_float.py | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index ac19353..1593f7b 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -445,6 +445,16 @@ class ComplexTest(unittest.TestCase): self.assertEqual(format(3+0j, ''), str(3+0j)) self.assertEqual(format(3.2+0j, ''), str(3.2+0j)) + # empty presentation type should still be analogous to str, + # even when format string is nonempty (issue #5920). + self.assertEqual(format(3.2+0j, '-'), str(3.2+0j)) + self.assertEqual(format(3.2+0j, '<'), str(3.2+0j)) + z = 4/7. - 100j/7. + self.assertEqual(format(z, ''), str(z)) + self.assertEqual(format(z, '-'), str(z)) + self.assertEqual(format(z, '<'), str(z)) + self.assertEqual(format(z, '10'), str(z)) + self.assertEqual(format(1+3j, 'g'), '1+3j') self.assertEqual(format(3j, 'g'), '0+3j') self.assertEqual(format(1.5+3.5j, 'g'), '1.5+3.5j') diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index fb6daaf..b617fa3 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -284,6 +284,13 @@ class FormatTestCase(unittest.TestCase): self.assertEqual(format(0.01, ''), '0.01') self.assertEqual(format(0.01, 'g'), '0.01') + # empty presentation type should format in the same way as str + # (issue 5920) + x = 100/7. + self.assertEqual(format(x, ''), str(x)) + self.assertEqual(format(x, '-'), str(x)) + self.assertEqual(format(x, '>'), str(x)) + self.assertEqual(format(x, '2'), str(x)) self.assertEqual(format(1.0, 'f'), '1.000000') |