mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #26331: Implement the parsing part of PEP 515.
Thanks to Georg Brandl for the patch.
This commit is contained in:
parent
ee73a65745
commit
a721abac29
22 changed files with 743 additions and 205 deletions
|
@ -554,6 +554,10 @@ class ExplicitConstructionTest(unittest.TestCase):
|
|||
self.assertEqual(str(Decimal(' -7.89')), '-7.89')
|
||||
self.assertEqual(str(Decimal(" 3.45679 ")), '3.45679')
|
||||
|
||||
# underscores
|
||||
self.assertEqual(str(Decimal('1_3.3e4_0')), '1.33E+41')
|
||||
self.assertEqual(str(Decimal('1_0_0_0')), '1000')
|
||||
|
||||
# unicode whitespace
|
||||
for lead in ["", ' ', '\u00a0', '\u205f']:
|
||||
for trail in ["", ' ', '\u00a0', '\u205f']:
|
||||
|
@ -578,6 +582,9 @@ class ExplicitConstructionTest(unittest.TestCase):
|
|||
# embedded NUL
|
||||
self.assertRaises(InvalidOperation, Decimal, "12\u00003")
|
||||
|
||||
# underscores don't prevent errors
|
||||
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
|
||||
|
||||
@cpython_only
|
||||
def test_from_legacy_strings(self):
|
||||
import _testcapi
|
||||
|
@ -772,6 +779,9 @@ class ExplicitConstructionTest(unittest.TestCase):
|
|||
self.assertRaises(InvalidOperation, nc.create_decimal, "xyz")
|
||||
self.assertRaises(ValueError, nc.create_decimal, (1, "xyz", -25))
|
||||
self.assertRaises(TypeError, nc.create_decimal, "1234", "5678")
|
||||
# no whitespace and underscore stripping is done with this method
|
||||
self.assertRaises(InvalidOperation, nc.create_decimal, " 1234")
|
||||
self.assertRaises(InvalidOperation, nc.create_decimal, "12_34")
|
||||
|
||||
# too many NaN payload digits
|
||||
nc.prec = 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue