Skip to content

Commit fc083d0

Browse files
committed
Address review comments
Use a simplified regex. Capture the integer part of the number in one group, then strip off leading 0's.
1 parent 87d3daa commit fc083d0

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Lib/fpformat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
__all__ = ["fix","sci","NotANumber"]
2020

2121
# Compiled regular expression to "decode" a number
22-
decoder = re.compile(r'^([-+]?)0*([1-9]\d*)?((?:\.\d*)?)(([eE][-+]?\d+)?)$')
22+
decoder = re.compile(r'^([-+]?)(\d*)?((?:\.\d*)?)(([eE][-+]?\d+)?)$')
2323
# \0 the whole thing
2424
# \1 leading sign or empty
2525
# \2 digits left of decimal point
@@ -41,8 +41,7 @@ def extract(s):
4141
res = decoder.match(s)
4242
if res is None: raise NotANumber, s
4343
sign, intpart, fraction, exppart = res.group(1,2,3,4)
44-
if intpart is None: # ([1-9]\d*)? may match nothing
45-
intpart = ''
44+
intpart = intpart.lstrip('0');
4645
if sign == '+': sign = ''
4746
if fraction: fraction = fraction[1:]
4847
if exppart: expo = int(exppart[1:])

0 commit comments

Comments
 (0)