Skip default fallback logic when cls is specified

`cls` will provide its own default serialization mechanism, passing a `cls`
Encoder class is now also a way to opt-out of our patching shenanigans and just
use your own code.

This will work, provided the library doing the JSON encoding isn't also using
their own custom class.
This commit is contained in:
Masen Furer 2024-10-31 13:52:00 -07:00
parent 726c70d01e
commit 6f3b550e88
No known key found for this signature in database
GPG Key ID: 2AE2BD5531FF94F4

View File

@ -3729,6 +3729,7 @@ def _json_dumps_wrapper(*args, **kwargs):
Returns:
The JSON string.
"""
if "cls" not in kwargs:
_orig_default = kwargs.pop("default", None)
def _default(obj):
@ -3743,6 +3744,7 @@ def _json_dumps_wrapper(*args, **kwargs):
pass
raise TypeError()
if "cls" not in kwargs:
kwargs["default"] = _default
return _orig_json_dumps(*args, **kwargs)