remove deprecated json encoding parameter
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 2bd7aed · Browse files · 2 files·+2 added−60 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+2 added−60 removed
- other:+2 added−60 removed
Provenance
- Commit
218534a- Tree
4c61dc3- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
2bd7aed
2 files changed+2 added−60 removed
modified:src/flask/json/__init__.py+1 added-60 removed
1 import dataclasses2 import decimal3-import io3 import json as _json4 import typing as t5 import uuid7-import warnings6 from datetime import date7 8 from jinja2.utils import htmlsafe_json_dumps as _jinja_htmlsafe_dumps9 from werkzeug.http import http_date111 unmodified lines121 ``app`` can be passed directly, rather than requiring an app122 context for configuration.123 """124 _dump_arg_defaults(kwargs, app=app)127- encoding = kwargs.pop("encoding", None)128- rv = _json.dumps(obj, **kwargs)125+ return _json.dumps(obj, **kwargs)126 130- if encoding is not None:131- warnings.warn(132- "'encoding' is deprecated and will be removed in Flask 2.1.",133- DeprecationWarning,134- stacklevel=2,135- )127 137- if isinstance(rv, str):138- return rv.encode(encoding) # type: ignore139-140- return rv141-142-128 def dump(129 obj: t.Any, fp: t.IO[str], app: t.Optional["Flask"] = None, **kwargs: t.Any130 ) -> None:131 """Serialize an object to JSON written to a file object.11 unmodified lines143 Writing to a binary file, and the ``encoding`` argument, is144 deprecated and will be removed in Flask 2.1.145 """146 _dump_arg_defaults(kwargs, app=app)162- encoding = kwargs.pop("encoding", None)163- show_warning = encoding is not None164-165- try:166- fp.write("")167- except TypeError:168- show_warning = True169- fp = io.TextIOWrapper(fp, encoding or "utf-8") # type: ignore170-171- if show_warning:172- warnings.warn(173- "Writing to a binary file, and the 'encoding' argument, is"174- " deprecated and will be removed in Flask 2.1.",175- DeprecationWarning,176- stacklevel=2,177- )178-147 _json.dump(obj, fp, **kwargs)148 149 150 def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:15 unmodified lines166 ``app`` can be passed directly, rather than requiring an app167 context for configuration.168 """169 _load_arg_defaults(kwargs, app=app)202- encoding = kwargs.pop("encoding", None)203-204- if encoding is not None:205- warnings.warn(206- "'encoding' is deprecated and will be removed in Flask 2.1."207- " The data must be a string or UTF-8 bytes.",208- DeprecationWarning,209- stacklevel=2,210- )211-212- if isinstance(s, bytes):213- s = s.decode(encoding)214-170 return _json.loads(s, **kwargs)171 172 173 def load(fp: t.IO[str], app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:11 unmodified lines185 ``encoding`` is deprecated and will be removed in Flask 2.1. The186 file must be text mode, or binary mode with UTF-8 bytes.187 """188 _load_arg_defaults(kwargs, app=app)234- encoding = kwargs.pop("encoding", None)235-236- if encoding is not None:237- warnings.warn(238- "'encoding' is deprecated and will be removed in Flask 2.1."239- " The file must be text mode, or binary mode with UTF-8"240- " bytes.",241- DeprecationWarning,242- stacklevel=2,243- )244-245- if isinstance(fp.read(0), bytes):246- fp = io.TextIOWrapper(fp, encoding) # type: ignore247-189 return _json.load(fp, **kwargs)190 191 192 def htmlsafe_dumps(obj: t.Any, **kwargs: t.Any) -> str:101 unmodified linesmodified:CHANGES.rst+1 added
10 unmodified lines11 12 - The CLI does not pass ``script_info`` to app factory functions.13 - ``config.from_json`` is replaced by14 ``config.from_file(name, load=json.load)``.15+ - ``json`` functions no longer take an ``encoding`` parameter.16 17 18 Version 2.0.219 -------------1180 unmodified lines