From 7ab934f6bc2380a322c77d92c0b6cfd10b7de991 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 21 May 2021 08:42:44 -0700 Subject: [PATCH] improve typing for `stream_with_context` --- CHANGES.rst | 1 + src/flask/helpers.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2698276eaa..9e9878927c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -35,6 +35,7 @@ Unreleased same blueprint to be registered multiple times with unique names for ``url_for``. Registering the same blueprint with the same name multiple times is deprecated. :issue:`1091` +- Improve typing for ``stream_with_context``. :issue:`4052` Version 2.0.0 diff --git a/src/flask/helpers.py b/src/flask/helpers.py index 57ec9ebf30..7b8b087021 100644 --- a/src/flask/helpers.py +++ b/src/flask/helpers.py @@ -64,8 +64,10 @@ def get_load_dotenv(default: bool = True) -> bool: def stream_with_context( - generator_or_function: t.Union[t.Generator, t.Callable] -) -> t.Generator: + generator_or_function: t.Union[ + t.Iterator[t.AnyStr], t.Callable[..., t.Iterator[t.AnyStr]] + ] +) -> t.Iterator[t.AnyStr]: """Request contexts disappear when the response is started on the server. This is done for efficiency reasons and to make it less likely to encounter memory leaks with badly written WSGI middlewares. The downside is that if