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

refactor: replace orjson support with msgspec #2170

Merged
merged 4 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor: replace orjson support with msgspec
  • Loading branch information
VincentRPS committed Jul 14, 2023
commit 0bd031343fd2d6c20e78ab7a79422acc372b36ff
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Optional Packages

* `PyNaCl <https://pypi.org/project/PyNaCl/>`__ (for voice support)
* `aiodns <https://pypi.org/project/aiodns/>`__, `brotlipy <https://pypi.org/project/brotlipy/>`__, `cchardet <https://pypi.org/project/cchardet/>`__ (for aiohttp speedup)
* `orjson <https://pypi.org/project/orjson/>`__ (for json speedup)
* `msgspec <https://pypi.org/project/msgspec/>`__ (for json speedup)

Please note that while installing voice support on Linux, you must install the following packages via your preferred package manager (e.g. ``apt``, ``dnf``, etc) BEFORE running the above commands:

Expand Down
12 changes: 6 additions & 6 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
from .errors import HTTPException, InvalidArgument

try:
import orjson
import msgspec
except ModuleNotFoundError:
HAS_ORJSON = False
HAS_MSGSPEC = False
else:
HAS_ORJSON = True
HAS_MSGSPEC = True


__all__ = (
Expand Down Expand Up @@ -662,12 +662,12 @@ def _bytes_to_base64_data(data: bytes) -> str:
return fmt.format(mime=mime, data=b64)


if HAS_ORJSON:
if HAS_MSGSPEC:

def _to_json(obj: Any) -> str: # type: ignore
return orjson.dumps(obj).decode("utf-8")
return msgspec.json.encode(obj).decode("utf-8")

_from_json = orjson.loads # type: ignore
_from_json = msgspec.json.decode # type: ignore

else:

Expand Down
4 changes: 2 additions & 2 deletions requirements/speed.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
orjson>=3.5.4
aiohttp[speedups]
msgspec~=0.17.0
aiohttp[speedups]