This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Justin.Lebar
Recipients Justin.Lebar, docs@python
Date 2012-09-26.21:40:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1348695643.05.0.172807817425.issue16057@psf.upfronthosting.co.za>
In-reply-to
Content
The JSONEncoder documentation says we can implement our own encoder as:

  >>> class ComplexEncoder(json.JSONEncoder):
  ...     def default(self, obj):
  ...         if isinstance(obj, complex):
  ...             return [obj.real, obj.imag]
  ...         return json.JSONEncoder.default(self, obj)

Later on, we give the following example of how to implement the default method in a subclass of json.JSONEncoder:

  def default(self, o):
  try:
      iterable = iter(o)
  except TypeError:
      pass
  else:
      return list(iterable)
  return JSONEncoder.default(self, o)

These are both incorrect, as a quick reading of the source will reveal.  JSONEncoder.default() throws for all input values.  We should s/JSONEncoder.default/JSONEncoder.encode/ here, I think.
History
Date User Action Args
2012-09-26 21:40:43Justin.Lebarsetrecipients: + Justin.Lebar, docs@python
2012-09-26 21:40:43Justin.Lebarsetmessageid: <1348695643.05.0.172807817425.issue16057@psf.upfronthosting.co.za>
2012-09-26 21:40:42Justin.Lebarlinkissue16057 messages
2012-09-26 21:40:41Justin.Lebarcreate