[Python-checkins] cpython: Cleanup json decoder: float() has builtin support of nan, +inf, -inf since

victor.stinner python-checkins at python.org
Thu Nov 29 00:13:22 CET 2012


http://hg.python.org/cpython/rev/402bae9f8fe5
changeset:   80633:402bae9f8fe5
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Nov 29 00:12:40 2012 +0100
summary:
  Cleanup json decoder: float() has builtin support of nan, +inf, -inf since Python 2.6

files:
  Lib/json/decoder.py |  14 +++-----------
  1 files changed, 3 insertions(+), 11 deletions(-)


diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -1,9 +1,6 @@
 """Implementation of JSONDecoder
 """
-import binascii
 import re
-import sys
-import struct
 
 from json import scanner
 try:
@@ -15,14 +12,9 @@
 
 FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
 
-def _floatconstants():
-    _BYTES = binascii.unhexlify(b'7FF80000000000007FF0000000000000')
-    if sys.byteorder != 'big':
-        _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
-    nan, inf = struct.unpack('dd', _BYTES)
-    return nan, inf, -inf
-
-NaN, PosInf, NegInf = _floatconstants()
+NaN = float('nan')
+PosInf = float('inf')
+NegInf = float('-inf')
 
 
 def linecol(doc, pos):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list