From 1617202d91e46a4c2584656969f90aa5d5db7fed Mon Sep 17 00:00:00 2001 From: David Lord Date: Mon, 8 Jul 2019 10:26:12 -0700 Subject: [PATCH 1/2] restore and deprecate json_available --- CHANGES.rst | 10 ++++++++++ src/flask/__init__.py | 3 ++- src/flask/_compat.py | 30 ++++++++++++++++++++++++++++++ tests/test_deprecations.py | 12 ++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/test_deprecations.py diff --git a/CHANGES.rst b/CHANGES.rst index 32dfdd65..54c09a67 100644 --- a/CHANGES.rst +++ b/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 ------------- diff --git a/src/flask/__init__.py b/src/flask/__init__.py index 7f5013e5..be3bac39 100644 --- a/src/flask/__init__.py +++ b/src/flask/__init__.py @@ -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" diff --git a/src/flask/_compat.py b/src/flask/_compat.py index ee47d821..76c442ca 100644 --- a/src/flask/_compat.py +++ b/src/flask/_compat.py @@ -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) diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py new file mode 100644 index 00000000..523ec109 --- /dev/null +++ b/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 From ffc68840f821fb0a4c41a7b2b4eaad6d71f539b7 Mon Sep 17 00:00:00 2001 From: David Lord Date: Mon, 8 Jul 2019 10:55:25 -0700 Subject: [PATCH 2/2] release version 1.1.1 --- CHANGES.rst | 2 +- README.rst | 4 ++-- setup.py | 2 +- src/flask/__init__.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 54c09a67..dddddbdc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,7 +3,7 @@ Version 1.1.1 ------------- -Unreleased +Released 2019-07-08 - The ``flask.json_available`` flag was added back for compatibility with some extensions. It will raise a deprecation warning when used, diff --git a/README.rst b/README.rst index 6e574323..ecfccedb 100644 --- a/README.rst +++ b/README.rst @@ -66,8 +66,8 @@ donate today`_. Links ----- -* Website: https://www.palletsprojects.com/p/flask/ -* Documentation: http://flask.pocoo.org/docs/ +* Website: https://palletsprojects.com/p/flask/ +* Documentation: https://flask.palletsprojects.com/ * Releases: https://pypi.org/project/Flask/ * Code: https://github.com/pallets/flask * Issue tracker: https://github.com/pallets/flask/issues diff --git a/setup.py b/setup.py index fa680a75..8a0b8ad4 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( version=version, url="https://palletsprojects.com/p/flask/", project_urls={ - "Documentation": "http://flask.palletsprojects.com/", + "Documentation": "https://flask.palletsprojects.com/", "Code": "https://github.com/pallets/flask", "Issue tracker": "https://github.com/pallets/flask/issues", }, diff --git a/src/flask/__init__.py b/src/flask/__init__.py index be3bac39..687475bc 100644 --- a/src/flask/__init__.py +++ b/src/flask/__init__.py @@ -57,4 +57,4 @@ from .signals import template_rendered from .templating import render_template from .templating import render_template_string -__version__ = "1.1.1.dev" +__version__ = "1.1.1"