Merge pull request #4042 from pallets/update-typing
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Update typing
authored by David Lord · committed by GitHub · parents c121e8c, 25884c4 · Browse files · 7 files·+77 added−49 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+77 added−49 removed
- other:+77 added−49 removed
Provenance
- Commit
6414df9- Tree
6d7f6d4- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
c121e8c- Parent 2
25884c4
7 files changed+77 added−49 removed
modified:src/flask/__init__.py+41 added-41 removed
1 from markupsafe import escape2 from markupsafe import Markup3-from werkzeug.exceptions import abort4-from werkzeug.utils import redirect3+from werkzeug.exceptions import abort as abort4+from werkzeug.utils import redirect as redirect5 6-from . import json7-from .app import Flask8-from .app import Request9-from .app import Response10-from .blueprints import Blueprint11-from .config import Config12-from .ctx import after_this_request13-from .ctx import copy_current_request_context14-from .ctx import has_app_context15-from .ctx import has_request_context16-from .globals import _app_ctx_stack17-from .globals import _request_ctx_stack18-from .globals import current_app19-from .globals import g20-from .globals import request21-from .globals import session22-from .helpers import flash23-from .helpers import get_flashed_messages24-from .helpers import get_template_attribute25-from .helpers import make_response26-from .helpers import safe_join27-from .helpers import send_file28-from .helpers import send_from_directory29-from .helpers import stream_with_context30-from .helpers import url_for31-from .json import jsonify32-from .signals import appcontext_popped33-from .signals import appcontext_pushed34-from .signals import appcontext_tearing_down35-from .signals import before_render_template36-from .signals import got_request_exception37-from .signals import message_flashed38-from .signals import request_finished39-from .signals import request_started40-from .signals import request_tearing_down41-from .signals import signals_available42-from .signals import template_rendered43-from .templating import render_template44-from .templating import render_template_string6+from . import json as json7+from .app import Flask as Flask8+from .app import Request as Request9+from .app import Response as Response10+from .blueprints import Blueprint as Blueprint11+from .config import Config as Config12+from .ctx import after_this_request as after_this_request13+from .ctx import copy_current_request_context as copy_current_request_context14+from .ctx import has_app_context as has_app_context15+from .ctx import has_request_context as has_request_context16+from .globals import _app_ctx_stack as _app_ctx_stack17+from .globals import _request_ctx_stack as _request_ctx_stack18+from .globals import current_app as current_app19+from .globals import g as g20+from .globals import request as request21+from .globals import session as session22+from .helpers import flash as flash23+from .helpers import get_flashed_messages as get_flashed_messages24+from .helpers import get_template_attribute as get_template_attribute25+from .helpers import make_response as make_response26+from .helpers import safe_join as safe_join27+from .helpers import send_file as send_file28+from .helpers import send_from_directory as send_from_directory29+from .helpers import stream_with_context as stream_with_context30+from .helpers import url_for as url_for31+from .json import jsonify as jsonify32+from .signals import appcontext_popped as appcontext_popped33+from .signals import appcontext_pushed as appcontext_pushed34+from .signals import appcontext_tearing_down as appcontext_tearing_down35+from .signals import before_render_template as before_render_template36+from .signals import got_request_exception as got_request_exception37+from .signals import message_flashed as message_flashed38+from .signals import request_finished as request_finished39+from .signals import request_started as request_started40+from .signals import request_tearing_down as request_tearing_down41+from .signals import signals_available as signals_available42+from .signals import template_rendered as template_rendered43+from .templating import render_template as render_template44+from .templating import render_template_string as render_template_string45 46 __version__ = "2.0.1.dev0"modified:src/flask/app.py+2 added-1 removed
70 unmodified lines71 from .wrappers import Request72 from .wrappers import Response73 74 if t.TYPE_CHECKING:75+ import typing_extensions as te76 from .blueprints import Blueprint77 from .testing import FlaskClient78 from .testing import FlaskCliRunner79 1361 unmodified lines1441 self.logger.error(1442 f"Exception on {request.path} [{request.method}]", exc_info=exc_info1443 )1444 1444- def raise_routing_exception(self, request: Request) -> t.NoReturn:1445+ def raise_routing_exception(self, request: Request) -> "te.NoReturn":1446 """Exceptions that are recording during routing are reraised with1447 this method. During debug we are not reraising redirect requests1448 for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising1449 a different error instead to help debug situations.627 unmodified linesmodified:src/flask/ctx.py+20 added-2 removed
39 unmodified lines40 41 .. versionadded:: 0.1042 """43 44+ # Define attr methods to let mypy know this is a namespace object45+ # that has arbitrary attributes.46+47+ def __getattr__(self, name: str) -> t.Any:48+ try:49+ return self.__dict__[name]50+ except KeyError:51+ raise AttributeError(name) from None52+53+ def __setattr__(self, name: str, value: t.Any) -> None:54+ self.__dict__[name] = value55+56+ def __delattr__(self, name: str) -> None:57+ try:58+ del self.__dict__[name]59+ except KeyError:60+ raise AttributeError(name) from None61+62 def get(self, name: str, default: t.Optional[t.Any] = None) -> t.Any:63 """Get an attribute by name, or a default value. Like64 :meth:`dict.get`.65 29 unmodified lines95 .. versionadded:: 0.1196 """97 return self.__dict__.setdefault(name, default)98 81- def __contains__(self, item: t.Any) -> bool:99+ def __contains__(self, item: str) -> bool:100 return item in self.__dict__101 84- def __iter__(self) -> t.Iterator:102+ def __iter__(self) -> t.Iterator[str]:103 return iter(self.__dict__)104 105 def __repr__(self) -> str:106 top = _app_ctx_stack.top372 unmodified linesmodified:src/flask/globals.py+5 added-3 removed
4 unmodified lines5 from werkzeug.local import LocalStack6 7 if t.TYPE_CHECKING:8 from .app import Flask9- from .ctx import AppContext9+ from .ctx import _AppCtxGlobals10 from .sessions import SessionMixin11 from .wrappers import Request12 13 _request_ctx_err_msg = """\38 unmodified lines52 _request_ctx_stack = LocalStack()53 _app_ctx_stack = LocalStack()54 current_app: "Flask" = LocalProxy(_find_app) # type: ignore55 request: "Request" = LocalProxy(partial(_lookup_req_object, "request")) # type: ignore56-session: "SessionMixin" = LocalProxy(partial(_lookup_req_object, "session")) # type: ignore # noqa: B95057-g: "AppContext" = LocalProxy(partial(_lookup_app_object, "g")) # type: ignore56+session: "SessionMixin" = LocalProxy( # type: ignore57+ partial(_lookup_req_object, "session")58+)59+g: "_AppCtxGlobals" = LocalProxy(partial(_lookup_app_object, "g")) # type: ignoremodified:src/flask/sessions.py+2 added-1 removed
10 unmodified lines11 from .helpers import is_ip12 from .json.tag import TaggedJSONSerializer13 14 if t.TYPE_CHECKING:15+ import typing_extensions as te16 from .app import Flask17 from .wrappers import Request, Response18 19 72 unmodified lines92 available. Will still allow read-only access to the empty session93 but fail on setting.94 """95 95- def _fail(self, *args: t.Any, **kwargs: t.Any) -> t.NoReturn:96+ def _fail(self, *args: t.Any, **kwargs: t.Any) -> "te.NoReturn":97 raise RuntimeError(98 "The session is unavailable because no secret "99 "key was set. Set the secret_key on the "100 "application to something unique and secret."304 unmodified linesmodified:src/flask/wrappers.py+2 added-1 removed
6 unmodified lines7 from . import json8 from .globals import current_app9 10 if t.TYPE_CHECKING:11+ import typing_extensions as te12 from werkzeug.routing import Rule13 14 15 class Request(RequestBase):75 unmodified lines91 from .debughelpers import attach_enctype_error_multidict92 93 attach_enctype_error_multidict(self)94 94- def on_json_loading_failed(self, e: Exception) -> t.NoReturn:95+ def on_json_loading_failed(self, e: Exception) -> "te.NoReturn":96 if current_app and current_app.debug:97 raise BadRequest(f"Failed to decode JSON object: {e}")98 99 raise BadRequest()36 unmodified linesmodified:CHANGES.rst+5 added
6 unmodified lines7 8 - Re-add the ``filename`` parameter in ``send_from_directory``. The9 ``filename`` parameter has been renamed to ``path``, the old name10 is deprecated. :pr:`4019`11+- Mark top-level names as exported so type checking understands12+ imports in user projects. :issue:`4024`13+- Fix type annotation for ``g`` and inform mypy that it is a namespace14+ object that has arbitrary attributes. :issue:`4020`15+- Fix some types that weren't available in Python 3.6.0. :issue:`4040`16 17 18 Version 2.0.019 -------------1096 unmodified lines