Skip to content

Mismatch between documentation and example code for Encoder::default(value) #108

Description

@daehlith

Hi,

the docs for the Encoder class say to raise a TypeError if it cannot return a JSON encodable version of value:

If implemented, this method is called whenever the serialization machinery finds a Python object that it does not recognize: if possible, the method should returns a JSON encodable version of the value, otherwise raise a TypeError

Yet, the example code provided raises a ValueError instead:

class PointEncoder(Encoder):
   def default(self, obj):
     if isinstance(obj, Point):
       return {'x': obj.x, 'y': obj.y}
     else:
       raise ValueError('%r is not JSON serializable' % obj)

IMHO the example should return a TypeError to be consistent with the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions