Merge pull request #3237 from scrosby/fix-3218

Move python properties to decorator syntax
This commit is contained in:
David Lord 2019-05-31 13:44:22 -04:00 committed by GitHub
commit cd4023d9d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 38 deletions

View file

@ -728,7 +728,8 @@ class Flask(_PackageBoundObject):
"""
return open(os.path.join(self.instance_path, resource), mode)
def _get_templates_auto_reload(self):
@property
def templates_auto_reload(self):
"""Reload templates when they are changed. Used by
:meth:`create_jinja_environment`.
@ -742,14 +743,10 @@ class Flask(_PackageBoundObject):
rv = self.config["TEMPLATES_AUTO_RELOAD"]
return rv if rv is not None else self.debug
def _set_templates_auto_reload(self, value):
@templates_auto_reload.setter
def templates_auto_reload(self, value):
self.config["TEMPLATES_AUTO_RELOAD"] = value
templates_auto_reload = property(
_get_templates_auto_reload, _set_templates_auto_reload
)
del _get_templates_auto_reload, _set_templates_auto_reload
def create_jinja_environment(self):
"""Create the Jinja environment based on :attr:`jinja_options`
and the various Jinja-related methods of the app. Changing
@ -856,28 +853,28 @@ class Flask(_PackageBoundObject):
#: Default: ``'production'``
env = ConfigAttribute("ENV")
def _get_debug(self):
@property
def debug(self):
"""Whether debug mode is enabled. When using ``flask run`` to start
the development server, an interactive debugger will be shown for
unhandled exceptions, and the server will be reloaded when code
changes. This maps to the :data:`DEBUG` config key. This is
enabled when :attr:`env` is ``'development'`` and is overridden
by the ``FLASK_DEBUG`` environment variable. It may not behave as
expected if set in code.
**Do not enable debug mode when deploying in production.**
Default: ``True`` if :attr:`env` is ``'development'``, or
``False`` otherwise.
"""
return self.config["DEBUG"]
def _set_debug(self, value):
@debug.setter
def debug(self, value):
self.config["DEBUG"] = value
self.jinja_env.auto_reload = self.templates_auto_reload
#: Whether debug mode is enabled. When using ``flask run`` to start
#: the development server, an interactive debugger will be shown for
#: unhandled exceptions, and the server will be reloaded when code
#: changes. This maps to the :data:`DEBUG` config key. This is
#: enabled when :attr:`env` is ``'development'`` and is overridden
#: by the ``FLASK_DEBUG`` environment variable. It may not behave as
#: expected if set in code.
#:
#: **Do not enable debug mode when deploying in production.**
#:
#: Default: ``True`` if :attr:`env` is ``'development'``, or
#: ``False`` otherwise.
debug = property(_get_debug, _set_debug)
del _get_debug, _set_debug
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
"""Runs the application on a local development server.

View file

@ -315,15 +315,14 @@ class RequestContext(object):
if self.url_adapter is not None:
self.match_request()
def _get_g(self):
@property
def g(self):
return _app_ctx_stack.top.g
def _set_g(self, value):
@g.setter
def g(self, value):
_app_ctx_stack.top.g = value
g = property(_get_g, _set_g)
del _get_g, _set_g
def copy(self):
"""Creates a copy of this request context with the same request object.
This can be used to move a request context to a different greenlet.

View file

@ -951,20 +951,16 @@ class _PackageBoundObject(object):
#: application has been discovered and blueprints registered.
self.cli = AppGroup()
def _get_static_folder(self):
@property
def static_folder(self):
"""The absolute path to the configured static folder."""
if self._static_folder is not None:
return os.path.join(self.root_path, self._static_folder)
def _set_static_folder(self, value):
@static_folder.setter
def static_folder(self, value):
self._static_folder = value
static_folder = property(
_get_static_folder,
_set_static_folder,
doc="The absolute path to the configured static folder.",
)
del _get_static_folder, _set_static_folder
@property
def static_url_path(self):
"""The URL prefix that the static route will be accessible from.