
On Thu, Aug 15, 2019 at 2:23 AM Random832 <random832@fastmail.com> wrote:
On Sun, Aug 11, 2019, at 20:42, Chris Angelico wrote:
class float: def __json__(self): if math.isfinite(self): return str(self) return "null"
Er, to be clear, the current JSON decoder returns 'Infinity', '-Infinity', or 'NaN', which are invalid JSON, not null. This behavior (vs raising an exception) is governed by a flag. I'm mainly bringing this up to point out that the concerns about a raw protocol being able to generate invalid JSON seem somewhat overblown and that "people should be able to generate invalid JSON if they want to" is not without precedent.
The examples I gave were meant to be toys, but you're right, this doesn't match current behaviour. For an actual PEP it would be better to be more accurate to the way json.dumps currently works; for this, I didn't really care too much :) Side point: Does anyone else think it was an egotistical idea to create JSON as a non-versioned specification? "I can't possibly get this wrong". And now look what's happened. ChrisA