Skip to content
Myr

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

2 files+2 added−60 removed

modified:src/flask/json/__init__.py+1 added-60 removed
1import dataclasses2import decimal3import io3import json as _json4import typing as t5import uuid7import warnings6from datetime import date78from jinja2.utils import htmlsafe_json_dumps as _jinja_htmlsafe_dumps9from werkzeug.http import http_date
111 unmodified lines
121 ``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)126130 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 )127137 if isinstance(rv, str):138 return rv.encode(encoding) # type: ignore139140 return rv141142128def 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 lines
143 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 None164165 try:166 fp.write("")167 except TypeError:168 show_warning = True169 fp = io.TextIOWrapper(fp, encoding or "utf-8") # type: ignore170171 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 )178147 _json.dump(obj, fp, **kwargs)148149150def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
15 unmodified lines
166 ``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)203204 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 )211212 if isinstance(s, bytes):213 s = s.decode(encoding)214170 return _json.loads(s, **kwargs)171172173def load(fp: t.IO[str], app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
11 unmodified lines
185 ``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)235236 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 )244245 if isinstance(fp.read(0), bytes):246 fp = io.TextIOWrapper(fp, encoding) # type: ignore247189 return _json.load(fp, **kwargs)190191192def htmlsafe_dumps(obj: t.Any, **kwargs: t.Any) -> str:
101 unmodified lines
modified:CHANGES.rst+1 added
10 unmodified lines
1112 - 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.161718Version 2.0.219-------------
1180 unmodified lines