Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json traceback on a float #82055

Closed
afonari mannequin opened this issue Aug 16, 2019 · 4 comments
Closed

json traceback on a float #82055

afonari mannequin opened this issue Aug 16, 2019 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@afonari
Copy link
Mannequin

afonari mannequin commented Aug 16, 2019

BPO 37874
Nosy @ericvsmith, @serhiy-storchaka, @afonari

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-08-16.14:29:06.752>
created_at = <Date 2019-08-16.14:22:41.264>
labels = ['invalid', 'type-bug', 'library']
title = 'json traceback on a float'
updated_at = <Date 2019-08-16.15:42:21.086>
user = 'https://github.com/afonari'

bugs.python.org fields:

activity = <Date 2019-08-16.15:42:21.086>
actor = 'af'
assignee = 'none'
closed = True
closed_date = <Date 2019-08-16.14:29:06.752>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2019-08-16.14:22:41.264>
creator = 'af'
dependencies = []
files = []
hgrepos = []
issue_num = 37874
keywords = []
message_count = 4.0
messages = ['349866', '349867', '349871', '349873']
nosy_count = 3.0
nosy_names = ['eric.smith', 'serhiy.storchaka', 'af']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue37874'
versions = ['Python 3.6']

@afonari
Copy link
Mannequin Author

afonari mannequin commented Aug 16, 2019

json.loads traceback with:

[In [16]: json.loads("[1.e-8]")
---------------------------------------------------------------------------

JSONDecodeError                           Traceback (most recent call last)
<ipython-input-16-bf0d3d6c51c5> in <module>()
----> 1 json.loads("[1.e-8]")

/scr/fonari/2019-4/internal/lib/python3.6/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
352 parse_int is None and parse_float is None and
353 parse_constant is None and object_pairs_hook is None and not kw):
--> 354 return _default_decoder.decode(s)
355 if cls is None:
356 cls = JSONDecoder

/scr/fonari/2019-4/internal/lib/python3.6/json/decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):

/scr/fonari/2019-4/internal/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
353 """
354 try:
--> 355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
357 raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting ',' delimiter: line 1 column 3 (char 2)

Works with json.loads("[1.0e-8]") and json.loads("[1e-8]")

@afonari afonari mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 16, 2019
@serhiy-storchaka
Copy link
Member

1.0e-8 is not a format for numbers in JSON. See RFC 7159 (https://tools.ietf.org/html/rfc7159.html#section-6):

      number = [ minus ] int [ frac ] [ exp ]
  decimal-point = %x2E       ; .

  digit1-9 = %x31-39         ; 1-9

  e = %x65 / %x45            ; e E
      exp = e [ minus / plus ] 1*DIGIT

      frac = decimal-point 1*DIGIT

      int = zero / ( digit1-9 *DIGIT )
  minus = %x2D               ; -

  plus = %x2B                ; +

  zero = %x30                ; 0

@ericvsmith
Copy link
Member

I think Serhiy means 1.e-8 is not valid.

The spec says that at least one digit is required in the "frac" part, after the decimal.

@afonari
Copy link
Mannequin Author

afonari mannequin commented Aug 16, 2019

I understand, thanks.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants