deprecate locked_cached_property
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent c690f52 · Browse files · 4 files·+22 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+22 added−6 removed
- other:+22 added−6 removed
Provenance
- Commit
4256fc6- Tree
2ba5513- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
c690f52
4 files changed+22 added−6 removed
modified:src/flask/app.py+4 added-4 removed
24 unmodified lines25 from werkzeug.routing import RoutingException26 from werkzeug.routing import Rule27 from werkzeug.serving import is_running_from_reloader28 from werkzeug.urls import url_quote29+from werkzeug.utils import cached_property30 from werkzeug.utils import redirect as _wz_redirect31 from werkzeug.wrappers import Response as BaseResponse32 33 from . import cli12 unmodified lines46 from .helpers import _split_blueprint_path47 from .helpers import get_debug_flag48 from .helpers import get_flashed_messages49 from .helpers import get_load_dotenv49-from .helpers import locked_cached_property50 from .json.provider import DefaultJSONProvider51 from .json.provider import JSONProvider52 from .logging import create_logger53 from .scaffold import _endpoint_from_view_func476 unmodified lines530 " needed to set up the application are done before"531 " running it."532 )533 534- @locked_cached_property534+ @cached_property535 def name(self) -> str: # type: ignore536 """The name of the application. This is usually the import name537 with the difference that it's guessed from the run file if the538 import name is main. This name is used as a display name when8 unmodified lines547 return "__main__"548 return os.path.splitext(os.path.basename(fn))[0]549 return self.import_name550 551- @locked_cached_property551+ @cached_property552 def logger(self) -> logging.Logger:553 """A standard Python :class:`~logging.Logger` for the app, with554 the same name as :attr:`name`.555 18 unmodified lines574 .. versionadded:: 0.3575 """576 return create_logger(self)577 578- @locked_cached_property578+ @cached_property579 def jinja_env(self) -> Environment:580 """The Jinja environment used to load templates.581 582 The environment is created the first time this property is1645 unmodified linesmodified:src/flask/helpers.py+12 added
611 unmodified lines612 """A :func:`property` that is only evaluated once. Like613 :class:`werkzeug.utils.cached_property` except access uses a lock614 for thread safety.615 616+ .. deprecated:: 2.3617+ Will be removed in Flask 2.4. Use a lock inside the decorated function if618+ locking is needed.619+620 .. versionchanged:: 2.0621 Inherits from Werkzeug's ``cached_property`` (and ``property``).622 """623 2 unmodified lines626 fget: t.Callable[[t.Any], t.Any],627 name: t.Optional[str] = None,628 doc: t.Optional[str] = None,629 ) -> None:630+ import warnings631+632+ warnings.warn(633+ "'locked_cached_property' is deprecated and will be removed in Flask 2.4."634+ " Use a lock inside the decorated function if locking is needed.",635+ DeprecationWarning,636+ stacklevel=2,637+ )638 super().__init__(fget, name=name, doc=doc)639 self.lock = RLock()640 641 def __get__(self, obj: object, type: type = None) -> t.Any: # type: ignore43 unmodified linesmodified:src/flask/scaffold.py+2 added-2 removed
9 unmodified lines10 11 from jinja2 import FileSystemLoader12 from werkzeug.exceptions import default_exceptions13 from werkzeug.exceptions import HTTPException14+from werkzeug.utils import cached_property15 16 from . import typing as ft17 from .cli import AppGroup18 from .globals import current_app19 from .helpers import get_root_path19-from .helpers import locked_cached_property20 from .helpers import send_from_directory21 from .templating import _default_template_ctx_processor22 23 if t.TYPE_CHECKING: # pragma: no cover292 unmodified lines316 return send_from_directory(317 t.cast(str, self.static_folder), filename, max_age=max_age318 )319 320- @locked_cached_property320+ @cached_property321 def jinja_loader(self) -> t.Optional[FileSystemLoader]:322 """The Jinja loader for this object's templates. By default this323 is a class :class:`jinja2.loaders.FileSystemLoader` to324 :attr:`template_folder` if it is set.597 unmodified linesmodified:CHANGES.rst+4 added
24 unmodified lines25 26 - Importing ``escape`` and ``Markup`` from ``flask`` is deprecated. Import them27 directly from ``markupsafe`` instead. :pr:`4996`28 - The ``app.got_first_request`` property is deprecated. :pr:`4997`29+- The ``locked_cached_property`` decorator is deprecated. Use a lock inside the30+ decorated function if locking is needed. :issue:`4993`31+- Remove uses of locks that could cause requests to block each other very briefly.32+ :issue:`4993`33 - Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.34 :pr:`4947`35 - Ensure subdomains are applied with nested blueprints. :issue:`4834`36 1418 unmodified lines