Move python properties to decorator syntax
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Scott Crosby · committed by Scott Crosby · parent af1b2ea · Browse files · 3 files·+30 added−38 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+30 added−38 removed
- other:+30 added−38 removed
Provenance
- Commit
55ad09c- Tree
182c161- Author
Scott Crosby <scrosby@twosigma.com>- Committer
Scott Crosby <scrosby@twosigma.com>- Parent
af1b2ea
3 files changed+30 added−38 removed
modified:flask/app.py+21 added-24 removed
725 unmodified lines726 :param mode: resource file opening mode, default is 'rb'.727 """728 return open(os.path.join(self.instance_path, resource), mode)729 730+ @property730- def _get_templates_auto_reload(self):731+ def templates_auto_reload(self):732 """Reload templates when they are changed. Used by733 :meth:`create_jinja_environment`.734 735 This attribute can be configured with :data:`TEMPLATES_AUTO_RELOAD`. If5 unmodified lines741 """742 rv = self.config["TEMPLATES_AUTO_RELOAD"]743 return rv if rv is not None else self.debug744 745+ @templates_auto_reload.setter744- def _set_templates_auto_reload(self, value):746+ def templates_auto_reload(self, value):747 self.config["TEMPLATES_AUTO_RELOAD"] = value748 747- templates_auto_reload = property(748- _get_templates_auto_reload, _set_templates_auto_reload749- )750- del _get_templates_auto_reload, _set_templates_auto_reload751-749 def create_jinja_environment(self):750 """Create the Jinja environment based on :attr:`jinja_options`751 and the various Jinja-related methods of the app. Changing752 :attr:`jinja_options` after this will have no effect. Also adds98 unmodified lines851 #:852 #: Default: ``'production'``853 env = ConfigAttribute("ENV")854 855+ @property858- def _get_debug(self):856+ def debug(self):857+ """Whether debug mode is enabled. When using ``flask run`` to start858+ the development server, an interactive debugger will be shown for859+ unhandled exceptions, and the server will be reloaded when code860+ changes. This maps to the :data:`DEBUG` config key. This is861+ enabled when :attr:`env` is ``'development'`` and is overridden862+ by the ``FLASK_DEBUG`` environment variable. It may not behave as863+ expected if set in code.864+865+ **Do not enable debug mode when deploying in production.**866+867+ Default: ``True`` if :attr:`env` is ``'development'``, or868+ ``False`` otherwise.869+ """870 return self.config["DEBUG"]871 872+ @debug.setter861- def _set_debug(self, value):873+ def debug(self, value):874 self.config["DEBUG"] = value875 self.jinja_env.auto_reload = self.templates_auto_reload876 865- #: Whether debug mode is enabled. When using ``flask run`` to start866- #: the development server, an interactive debugger will be shown for867- #: unhandled exceptions, and the server will be reloaded when code868- #: changes. This maps to the :data:`DEBUG` config key. This is869- #: enabled when :attr:`env` is ``'development'`` and is overridden870- #: by the ``FLASK_DEBUG`` environment variable. It may not behave as871- #: expected if set in code.872- #:873- #: **Do not enable debug mode when deploying in production.**874- #:875- #: Default: ``True`` if :attr:`env` is ``'development'``, or876- #: ``False`` otherwise.877- debug = property(_get_debug, _set_debug)878- del _get_debug, _set_debug879-877 def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):878 """Runs the application on a local development server.879 880 Do not use ``run()`` in a production setting. It is not intended to1530 unmodified linesmodified:flask/ctx.py+4 added-5 removed
313 unmodified lines314 315 if self.url_adapter is not None:316 self.match_request()317 318+ @property318- def _get_g(self):319+ def g(self):320 return _app_ctx_stack.top.g321 322+ @g.setter321- def _set_g(self, value):323+ def g(self, value):324 _app_ctx_stack.top.g = value325 324- g = property(_get_g, _set_g)325- del _get_g, _set_g326-326 def copy(self):327 """Creates a copy of this request context with the same request object.328 This can be used to move a request context to a different greenlet.329 Because the actual request object is the same this cannot be used to143 unmodified linesmodified:flask/helpers.py+5 added-9 removed
949 unmodified lines950 #: are accessible via the :command:`flask` command once the951 #: application has been discovered and blueprints registered.952 self.cli = AppGroup()953 954+ @property954- def _get_static_folder(self):955+ def static_folder(self):956+ """The absolute path to the configured static folder."""957 if self._static_folder is not None:958 return os.path.join(self.root_path, self._static_folder)959 960+ @static_folder.setter958- def _set_static_folder(self, value):961+ def static_folder(self, value):962 self._static_folder = value963 961- static_folder = property(962- _get_static_folder,963- _set_static_folder,964- doc="The absolute path to the configured static folder.",965- )966- del _get_static_folder, _set_static_folder967-964 @property965 def static_url_path(self):966 """The URL prefix that the static route will be accessible from.967 145 unmodified lines