Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore and deprecate json_available #3292

Merged
merged 1 commit into from Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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