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

L is not JSON-serializable #531

Open
criemen opened this issue Jun 29, 2023 · 3 comments
Open

L is not JSON-serializable #531

criemen opened this issue Jun 29, 2023 · 3 comments

Comments

@criemen
Copy link

criemen commented Jun 29, 2023

The documentation for L claims that it is a drop-in for list operations.
Unfortunately, that's not entirely true, unlike true lists, L is not JSON-serializable:

Traceback (most recent call last):
  File "/Users/criemen/repos/codeql-halo/plugins/custom_github/operators/actions.py", line 121, in workflow_finished
    artifacts_str = xtras.dumps(artifacts)
  File "/opt/homebrew/lib/python3.10/site-packages/fastcore/xtras.py", line 152, in dumps
    return json.dumps(obj, **kw)
  File "/opt/homebrew/Cellar/[email protected]/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/opt/homebrew/Cellar/[email protected]/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/homebrew/Cellar/[email protected]/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/opt/homebrew/Cellar/[email protected]/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type L is not JSON serializable

This is rather annoying, as ghapi apparently returns L objects, instead of python lists, and besides a recursive traversal of the resulting object that I'd have to write myself, I've not found any easy way to convert an object/dist into something that I can JSON-serialize. Can you help me?
Is there any way you can make L work with JSON serialization? It doesn't work with json.dumps, and not even with your own xtras.dumps either 😞

@fzyzcjy
Copy link

fzyzcjy commented Aug 2, 2023

Hi I am seeing the same problem, did you solve it?

@fzyzcjy
Copy link

fzyzcjy commented Aug 2, 2023

Ok I see AnswerDotAI/ghapi#66

@criemen
Copy link
Author

criemen commented Aug 2, 2023

Nope, I switched over to https://github.com/yanyongyu/githubkit instead (my L instances came from the GH API client).

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

2 participants