Skip to content

Commit

Permalink
Merge pull request #3292 from pallets/deprecate-json-available
Browse files Browse the repository at this point in the history
restore and deprecate json_available
  • Loading branch information
davidism committed Jul 8, 2019
2 parents 1b4ace9 + 1617202 commit 1a6696d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGES.rst
@@ -1,5 +1,15 @@
.. currentmodule:: flask

Version 1.1.1
-------------

Unreleased

- The ``flask.json_available`` flag was added back for compatibility
with some extensions. It will raise a deprecation warning when used,
and will be removed in version 2.0.0. :issue:`3288`


Version 1.1.0
-------------

Expand Down
3 changes: 2 additions & 1 deletion src/flask/__init__.py
Expand Up @@ -17,6 +17,7 @@
from werkzeug.utils import redirect

from . import json
from ._compat import json_available
from .app import Flask
from .app import Request
from .app import Response
Expand Down Expand Up @@ -56,4 +57,4 @@
from .templating import render_template
from .templating import render_template_string

__version__ = "1.1.0"
__version__ = "1.1.1.dev"
30 changes: 30 additions & 0 deletions src/flask/_compat.py
Expand Up @@ -113,3 +113,33 @@ def __exit__(self, *args):
# https://www.python.org/dev/peps/pep-0519/#backwards-compatibility
def fspath(path):
return path.__fspath__() if hasattr(path, "__fspath__") else path


class _DeprecatedBool(object):
def __init__(self, name, version, value):
self.message = "'{}' is deprecated and will be removed in version {}.".format(
name, version
)
self.value = value

def _warn(self):
import warnings

warnings.warn(self.message, DeprecationWarning, stacklevel=2)

def __eq__(self, other):
self._warn()
return other == self.value

def __ne__(self, other):
self._warn()
return other != self.value

def __bool__(self):
self._warn()
return self.value

__nonzero__ = __bool__


json_available = _DeprecatedBool("flask.json_available", "2.0.0", True)
12 changes: 12 additions & 0 deletions tests/test_deprecations.py
@@ -0,0 +1,12 @@
import pytest

from flask import json_available


def test_json_available():
with pytest.deprecated_call() as rec:
assert json_available
assert json_available == True # noqa E712
assert json_available != False # noqa E712

assert len(rec.list) == 3

0 comments on commit 1a6696d

Please sign in to comment.