Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8690fb

Browse files
committed
Define NotANumber as a subclass of ValueError when using class-based
exceptions. When raising NotANumber, pass the string that failed as the exception value.
1 parent 9e0b622 commit b8690fb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/fpformat.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
# \3 fraction (empty or begins with point)
2222
# \4 exponent part (empty or begins with 'e' or 'E')
2323

24-
NotANumber = 'fpformat.NotANumber'
24+
try:
25+
class NotANumber(ValueError):
26+
pass
27+
except TypeError:
28+
NotANumber = 'fpformat.NotANumber'
2529

2630
# Return (sign, intpart, fraction, expo) or raise an exception:
2731
# sign is '+' or '-'
@@ -30,7 +34,7 @@
3034
# expo is an integer
3135
def extract(s):
3236
res = decoder.match(s)
33-
if res is None: raise NotANumber
37+
if res is None: raise NotANumber, s
3438
sign, intpart, fraction, exppart = res.group(1,2,3,4)
3539
if sign == '+': sign = ''
3640
if fraction: fraction = fraction[1:]

0 commit comments

Comments
 (0)