Merge pull request #4342 from pallets/deprecate-req-ctx-g

deprecate `RequestContext.g`
This commit is contained in:
David Lord 2021-11-16 07:38:42 -08:00 committed by GitHub
commit 9486b6cf57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -29,6 +29,8 @@ Unreleased
- ``add_etags`` is renamed to ``etag``.
- ``filename`` is renamed to ``path``.
- The ``RequestContext.g`` property is deprecated. Use ``g`` directly
or ``AppContext.g`` instead. :issue:`3898`
- ``copy_current_request_context`` can decorate async functions.
:pr:`4303`

View file

@ -332,11 +332,29 @@ class RequestContext:
self._after_request_functions: t.List[AfterRequestCallable] = []
@property
def g(self) -> AppContext:
def g(self) -> _AppCtxGlobals:
import warnings
warnings.warn(
"Accessing 'g' on the request context is deprecated and"
" will be removed in Flask 2.2. Access `g` directly or from"
"the application context instead.",
DeprecationWarning,
stacklevel=2,
)
return _app_ctx_stack.top.g
@g.setter
def g(self, value: AppContext) -> None:
def g(self, value: _AppCtxGlobals) -> None:
import warnings
warnings.warn(
"Setting 'g' on the request context is deprecated and"
" will be removed in Flask 2.2. Set it on the application"
" context instead.",
DeprecationWarning,
stacklevel=2,
)
_app_ctx_stack.top.g = value
def copy(self) -> "RequestContext":