From 10425fb9b13d977128f18c1051fb93edc9aee2de Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 20 May 2021 12:35:43 -0700 Subject: [PATCH] re-add deprecated Config.from_json method --- CHANGES.rst | 2 ++ src/flask/config.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index fa24b104..0b5a939d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,6 +23,8 @@ Unreleased - Roll back a change to the order that URL matching was done. The URL is again matched after the session is loaded, so the session is available in custom URL converters. :issue:`4053` +- Re-add deprecated ``Config.from_json``, which was accidentally + removed early. :issue:`4078` Version 2.0.0 diff --git a/src/flask/config.py b/src/flask/config.py index 86f21dc8..c79a558e 100644 --- a/src/flask/config.py +++ b/src/flask/config.py @@ -202,6 +202,31 @@ class Config(dict): return self.from_mapping(obj) + def from_json(self, filename: str, silent: bool = False) -> bool: + """Update the values in the config from a JSON file. The loaded + data is passed to the :meth:`from_mapping` method. + + :param filename: The path to the JSON file. This can be an + absolute path or relative to the config root path. + :param silent: Ignore the file if it doesn't exist. + + .. deprecated:: 2.0.0 + Will be removed in Flask 2.1. Use :meth:`from_file` instead. + This was removed early in 2.0.0, was added back in 2.0.1. + + .. versionadded:: 0.11 + """ + import warnings + from . import json + + warnings.warn( + "'from_json' is deprecated and will be removed in Flask" + " 2.1. Use 'from_file(path, json.load)' instead.", + DeprecationWarning, + stacklevel=2, + ) + return self.from_file(filename, json.load, silent=silent) + def from_mapping( self, mapping: t.Optional[t.Mapping[str, t.Any]] = None, **kwargs: t.Any ) -> bool: