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

Example from README fails #2

Open
vikmary opened this issue Jun 29, 2020 · 0 comments
Open

Example from README fails #2

vikmary opened this issue Jun 29, 2020 · 0 comments

Comments

@vikmary
Copy link

vikmary commented Jun 29, 2020

Hi Dmitriy!

Unfortunately, the following example fails for me.

import fast_json
from collections import namedtuple


MyType = namedtuple("MyType", ["name", "value"])


@fast_json.convert.register(MyType)
def _(value):
    return "name={0.name} value={0.value}".format(value)


print(
    fast_json.dumps({
        "one": MyType(name="foo", value="bar")
    })
)

outputs {"one": ["foo", "bar"]}

This might be due to new code in json for Python 3.8 https://github.com/python/cpython/blob/3.8/Lib/json/encoder.py

You might want to update python_requires='<=3.7 in setup.py, or adapt to new code.

The problem in new json realization might be that default method gets invoked only if general parsing failed (but it doesn't fail for namedtuples).

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant