Skip to content

Incorrect serialization of float subclass with custom __str__ method #57

@ryanmarquardt

Description

@ryanmarquardt

I have a float subclass with a customized str method, and its str output is appearing in the results of json5.dumps. Here's a simplified example:

>>> import json5
>>> class MyFloat(float):
...     def __str__(self):
...         return f"<{super().__str__()}>"

>>> print(json5.dumps(MyFloat(1)))
<1.0>

>>> json5.loads(json5.dumps(MyFloat(1))
Traceback (most recent call last):
...
ValueError: <string>:1 Unexpected "<" at column 1

Metadata

Metadata

Assignees

Labels

availableIndicates which bugs have been triaged and reproduced, rather than just filedbug

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions