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

Does it make sense to make Python 3 dict_keys serializable? #55

Open
msabramo opened this issue Feb 12, 2013 · 3 comments
Open

Does it make sense to make Python 3 dict_keys serializable? #55

msabramo opened this issue Feb 12, 2013 · 3 comments

Comments

@msabramo
Copy link

I ran into an issue porting a project to Python 3, where simplejson raises a TypeError because of dict_keys:

  File "/Users/marca/dev/git-repos/cornice/.tox/py33/lib/python3.3/site-packages/simplejson/encoder.py", line 226, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: dict_keys([1, 2]) is not JSON serializable

This is easily fixed in the project by wrapping the dict_keys with list and that's fine, but I wonder if it makes sense to do it in simplejson as a convenience to make porting to Python 3 easier.

I could submit a PR if this is deemed useful, but I wanted to check first and make sure that this makes sense, wouldn't hurt performance too much, etc.

@etrepum
Copy link
Member

etrepum commented Feb 12, 2013

Not sure this makes sense, it's the first time that this has come up.

I'd prefer not to add special cases for things like this unless there really was a lot of demand for it. Types like this are pretty opaque and it's hard to test for them.

@etrepum etrepum closed this as completed Feb 12, 2013
@p3ngu1nx
Copy link

p3ngu1nx commented Oct 8, 2018

I have the same problem

@etrepum etrepum reopened this Oct 9, 2018
@vsajip
Copy link

vsajip commented Oct 9, 2018

The encoding of dicts happens via iteration AFAIK, so is this a case where @msabramo, @boriza the code in question explicitly tries to encode the result of some_dict.keys(), rather than encoding some_dict?

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

4 participants