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

Add alias to json.JSONEncoder to drop-in API. #118

Open
charlesjhill opened this issue Aug 21, 2024 · 0 comments
Open

Add alias to json.JSONEncoder to drop-in API. #118

charlesjhill opened this issue Aug 21, 2024 · 0 comments

Comments

@charlesjhill
Copy link

The docs explicitly call out a Drop-in API which will "just work". This module covers json.{load,loads,dump,dumps}, where {dump,dumps} are aliased to the built-in module. I propose adding an alias to json.JSONEncoder to make the drop-in API more complete. I don't think this should be problematic as one would only use a JSONEncoder for the dump/s commands, which are already aliased.

In a current project, I have something like this:

from json import JSONEncoder
try:
  import simdjson as json
except ImportError:
  import json

class CustomEncoder(JSONEncoder):
  ...

If an alias is added, the above snippet would be:

try:
  import simdjson as json
except ImportError:
  import json

class CustomEncoder(json.JSONEncoder):
  ...

It's a rather minor tweak, but I think it would be nice for developer experience.

Cheers

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