summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_compile.py44
-rw-r--r--Lib/tokenize.py4
2 files changed, 46 insertions, 2 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 0276ba6..9f20ba1 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -65,3 +65,47 @@ expect_error("2e")
expect_error("2.0e+")
expect_error("1e-")
expect_error("3-4e/21")
+
+
+if verbose:
+ print "testing literals with leading zeroes"
+
+def expect_same(test_source, expected):
+ got = eval(test_source)
+ if got != expected:
+ raise TestFailed("eval(%r) gave %r, but expected %r" %
+ (test_source, got, expected))
+
+expect_error("077787")
+expect_error("0xj")
+expect_error("0x.")
+expect_error("0e")
+expect_same("0777", 511)
+expect_same("0777L", 511)
+expect_same("000777", 511)
+expect_same("0xff", 255)
+expect_same("0xffL", 255)
+expect_same("0XfF", 255)
+expect_same("0777.", 777)
+expect_same("0777.0", 777)
+expect_same("000000000000000000000000000000000000000000000000000777e0", 777)
+expect_same("0777e1", 7770)
+expect_same("0e0", 0)
+expect_same("0000E-012", 0)
+expect_same("09.5", 9.5)
+expect_same("0777j", 777j)
+expect_same("00j", 0j)
+expect_same("00.0", 0)
+expect_same("0e3", 0)
+expect_same("090000000000000.", 90000000000000.)
+expect_same("090000000000000.0000000000000000000000", 90000000000000.)
+expect_same("090000000000000e0", 90000000000000.)
+expect_same("090000000000000e-0", 90000000000000.)
+expect_same("090000000000000j", 90000000000000j)
+expect_error("090000000000000") # plain octal literal w/ decimal digit
+expect_error("080000000000000") # plain octal literal w/ decimal digit
+expect_error("000000000000009") # plain octal literal w/ decimal digit
+expect_error("000000000000008") # plain octal literal w/ decimal digit
+expect_same("000000000000007", 7)
+expect_same("000000000000008.", 8.)
+expect_same("000000000000009.", 9.)
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index b952b36..da2bcd2 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -56,9 +56,9 @@ Decnumber = r'[1-9]\d*[lL]?'
Intnumber = group(Hexnumber, Octnumber, Decnumber)
Exponent = r'[eE][-+]?\d+'
Pointfloat = group(r'\d+\.\d*', r'\.\d+') + maybe(Exponent)
-Expfloat = r'[1-9]\d*' + Exponent
+Expfloat = r'\d+' + Exponent
Floatnumber = group(Pointfloat, Expfloat)
-Imagnumber = group(r'0[jJ]', r'[1-9]\d*[jJ]', Floatnumber + r'[jJ]')
+Imagnumber = group(r'\d+[jJ]', Floatnumber + r'[jJ]')
Number = group(Imagnumber, Floatnumber, Intnumber)
# Tail end of ' string.