From 25884c433f1eddf4537694d4c5f9f78cd9a14955 Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 13 May 2021 12:53:32 -0700 Subject: [PATCH] fix typing that wasn't available in Python 3.6.0 --- CHANGES.rst | 1 + src/flask/app.py | 3 ++- src/flask/sessions.py | 3 ++- src/flask/wrappers.py | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2214dc49..1c4a7558 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,7 @@ Unreleased imports in user projects. :issue:`4024` - Fix type annotation for ``g`` and inform mypy that it is a namespace object that has arbitrary attributes. :issue:`4020` +- Fix some types that weren't available in Python 3.6.0. :issue:`4040` Version 2.0.0 diff --git a/src/flask/app.py b/src/flask/app.py index f8856a52..f0f31486 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -72,6 +72,7 @@ from .wrappers import Request from .wrappers import Response if t.TYPE_CHECKING: + import typing_extensions as te from .blueprints import Blueprint from .testing import FlaskClient from .testing import FlaskCliRunner @@ -1441,7 +1442,7 @@ class Flask(Scaffold): f"Exception on {request.path} [{request.method}]", exc_info=exc_info ) - def raise_routing_exception(self, request: Request) -> t.NoReturn: + def raise_routing_exception(self, request: Request) -> "te.NoReturn": """Exceptions that are recording during routing are reraised with this method. During debug we are not reraising redirect requests for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising diff --git a/src/flask/sessions.py b/src/flask/sessions.py index 0e68e884..34b1d0ce 100644 --- a/src/flask/sessions.py +++ b/src/flask/sessions.py @@ -12,6 +12,7 @@ from .helpers import is_ip from .json.tag import TaggedJSONSerializer if t.TYPE_CHECKING: + import typing_extensions as te from .app import Flask from .wrappers import Request, Response @@ -92,7 +93,7 @@ class NullSession(SecureCookieSession): but fail on setting. """ - def _fail(self, *args: t.Any, **kwargs: t.Any) -> t.NoReturn: + def _fail(self, *args: t.Any, **kwargs: t.Any) -> "te.NoReturn": raise RuntimeError( "The session is unavailable because no secret " "key was set. Set the secret_key on the " diff --git a/src/flask/wrappers.py b/src/flask/wrappers.py index 48fcc34b..bfa9d7ce 100644 --- a/src/flask/wrappers.py +++ b/src/flask/wrappers.py @@ -8,6 +8,7 @@ from . import json from .globals import current_app if t.TYPE_CHECKING: + import typing_extensions as te from werkzeug.routing import Rule @@ -91,7 +92,7 @@ class Request(RequestBase): attach_enctype_error_multidict(self) - def on_json_loading_failed(self, e: Exception) -> t.NoReturn: + def on_json_loading_failed(self, e: Exception) -> "te.NoReturn": if current_app and current_app.debug: raise BadRequest(f"Failed to decode JSON object: {e}")