mirror of https://github.com/pallets/flask.git
Merge pull request #4350 from olliemath/patch-1
Only use a custom JSONDecoder if needed
This commit is contained in:
commit
7b0c82dfdc
|
@ -12,6 +12,9 @@ Unreleased
|
|||
- Fix type annotation for ``errorhandler`` decorator. :issue:`4295`
|
||||
- Revert a change to the CLI that caused it to hide ``ImportError``
|
||||
tracebacks when importing the application. :issue:`4307`
|
||||
- ``app.json_encoder`` and ``json_decoder`` are only passed to
|
||||
``dumps`` and ``loads`` if they have custom behavior. This improves
|
||||
performance, mainly on PyPy. :issue:`4349`
|
||||
|
||||
|
||||
Version 2.0.2
|
||||
|
|
|
@ -81,6 +81,11 @@ def _dump_arg_defaults(
|
|||
if bp is not None and bp.json_encoder is not None:
|
||||
cls = bp.json_encoder
|
||||
|
||||
# Only set a custom encoder if it has custom behavior. This is
|
||||
# faster on PyPy.
|
||||
if cls is not _json.JSONEncoder:
|
||||
kwargs.setdefault("cls", cls)
|
||||
|
||||
kwargs.setdefault("cls", cls)
|
||||
kwargs.setdefault("ensure_ascii", app.config["JSON_AS_ASCII"])
|
||||
kwargs.setdefault("sort_keys", app.config["JSON_SORT_KEYS"])
|
||||
|
@ -102,9 +107,10 @@ def _load_arg_defaults(
|
|||
if bp is not None and bp.json_decoder is not None:
|
||||
cls = bp.json_decoder
|
||||
|
||||
kwargs.setdefault("cls", cls)
|
||||
else:
|
||||
kwargs.setdefault("cls", JSONDecoder)
|
||||
# Only set a custom decoder if it has custom behavior. This is
|
||||
# faster on PyPy.
|
||||
if cls not in {JSONDecoder, _json.JSONDecoder}:
|
||||
kwargs.setdefault("cls", cls)
|
||||
|
||||
|
||||
def dumps(obj: t.Any, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> str:
|
||||
|
|
Loading…
Reference in New Issue