Skip to content

Commit 1a6696d

Browse files
authored
Merge pull request #3292 from pallets/deprecate-json-available
restore and deprecate json_available
2 parents 1b4ace9 + 1617202 commit 1a6696d

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

CHANGES.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
.. currentmodule:: flask
22

3+
Version 1.1.1
4+
-------------
5+
6+
Unreleased
7+
8+
- The ``flask.json_available`` flag was added back for compatibility
9+
with some extensions. It will raise a deprecation warning when used,
10+
and will be removed in version 2.0.0. :issue:`3288`
11+
12+
313
Version 1.1.0
414
-------------
515

src/flask/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from werkzeug.utils import redirect
1818

1919
from . import json
20+
from ._compat import json_available
2021
from .app import Flask
2122
from .app import Request
2223
from .app import Response
@@ -56,4 +57,4 @@
5657
from .templating import render_template
5758
from .templating import render_template_string
5859

59-
__version__ = "1.1.0"
60+
__version__ = "1.1.1.dev"

src/flask/_compat.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,33 @@ def __exit__(self, *args):
113113
# https://www.python.org/dev/peps/pep-0519/#backwards-compatibility
114114
def fspath(path):
115115
return path.__fspath__() if hasattr(path, "__fspath__") else path
116+
117+
118+
class _DeprecatedBool(object):
119+
def __init__(self, name, version, value):
120+
self.message = "'{}' is deprecated and will be removed in version {}.".format(
121+
name, version
122+
)
123+
self.value = value
124+
125+
def _warn(self):
126+
import warnings
127+
128+
warnings.warn(self.message, DeprecationWarning, stacklevel=2)
129+
130+
def __eq__(self, other):
131+
self._warn()
132+
return other == self.value
133+
134+
def __ne__(self, other):
135+
self._warn()
136+
return other != self.value
137+
138+
def __bool__(self):
139+
self._warn()
140+
return self.value
141+
142+
__nonzero__ = __bool__
143+
144+
145+
json_available = _DeprecatedBool("flask.json_available", "2.0.0", True)

tests/test_deprecations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
from flask import json_available
4+
5+
6+
def test_json_available():
7+
with pytest.deprecated_call() as rec:
8+
assert json_available
9+
assert json_available == True # noqa E712
10+
assert json_available != False # noqa E712
11+
12+
assert len(rec.list) == 3

0 commit comments

Comments
 (0)