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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -94,6 +94,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2087](https://github.com/Pycord-Development/pycord/pull/2087))
- Typehinted `command_prefix` and `help_command` arguments properly.
([#2099](https://github.com/Pycord-Development/pycord/pull/2099))
- Replace `orjson` support with `msgspec` support.
([#2170](https://github.com/Pycord-Development/pycord/pull/2170))

### Removed

Expand Down
2 changes: 1 addition & 1 deletion README.rst
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
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
2 changes: 1 addition & 1 deletion requirements/speed.txt
@@ -1,2 +1,2 @@
orjson>=3.5.4
msgspec~=0.17.0
aiohttp[speedups]