Kaydet (Commit) b8690fbc authored tarafından Fred Drake's avatar Fred Drake

Define NotANumber as a subclass of ValueError when using class-based

exceptions.

When raising NotANumber, pass the string that failed as the exception
value.
üst 9e0b6229
...@@ -21,7 +21,11 @@ decoder = re.compile(r'^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$') ...@@ -21,7 +21,11 @@ decoder = re.compile(r'^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$')
# \3 fraction (empty or begins with point) # \3 fraction (empty or begins with point)
# \4 exponent part (empty or begins with 'e' or 'E') # \4 exponent part (empty or begins with 'e' or 'E')
NotANumber = 'fpformat.NotANumber' try:
class NotANumber(ValueError):
pass
except TypeError:
NotANumber = 'fpformat.NotANumber'
# Return (sign, intpart, fraction, expo) or raise an exception: # Return (sign, intpart, fraction, expo) or raise an exception:
# sign is '+' or '-' # sign is '+' or '-'
...@@ -30,7 +34,7 @@ NotANumber = 'fpformat.NotANumber' ...@@ -30,7 +34,7 @@ NotANumber = 'fpformat.NotANumber'
# expo is an integer # expo is an integer
def extract(s): def extract(s):
res = decoder.match(s) res = decoder.match(s)
if res is None: raise NotANumber if res is None: raise NotANumber, s
sign, intpart, fraction, exppart = res.group(1,2,3,4) sign, intpart, fraction, exppart = res.group(1,2,3,4)
if sign == '+': sign = '' if sign == '+': sign = ''
if fraction: fraction = fraction[1:] if fraction: fraction = fraction[1:]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment