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

Skip to content

Commit d7fed37

Browse files
committed
Cleanup json decoder: float() has builtin support of nan, +inf, -inf since Python 2.6
1 parent 9f94b6d commit d7fed37

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

Lib/json/decoder.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
"""Implementation of JSONDecoder
22
"""
3-
import binascii
43
import re
5-
import sys
6-
import struct
74

85
from json import scanner
96
try:
@@ -15,14 +12,9 @@
1512

1613
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
1714

18-
def _floatconstants():
19-
_BYTES = binascii.unhexlify(b'7FF80000000000007FF0000000000000')
20-
if sys.byteorder != 'big':
21-
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
22-
nan, inf = struct.unpack('dd', _BYTES)
23-
return nan, inf, -inf
24-
25-
NaN, PosInf, NegInf = _floatconstants()
15+
NaN = float('nan')
16+
PosInf = float('inf')
17+
NegInf = float('-inf')
2618

2719

2820
def linecol(doc, pos):

0 commit comments

Comments
 (0)