forked from orbit-oss/flask
restore and deprecate json_available
This commit is contained in:
parent
1b4ace9ba5
commit
1617202d91
4 changed files with 54 additions and 1 deletions
10
CHANGES.rst
10
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
|
||||
-------------
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ from werkzeug.exceptions import abort
|
|||
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
|
||||
|
|
@ -56,4 +57,4 @@ from .signals import template_rendered
|
|||
from .templating import render_template
|
||||
from .templating import render_template_string
|
||||
|
||||
__version__ = "1.1.0"
|
||||
__version__ = "1.1.1.dev"
|
||||
|
|
|
|||
|
|
@ -113,3 +113,33 @@ except ImportError:
|
|||
# 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
tests/test_deprecations.py
Normal file
12
tests/test_deprecations.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue