Skip to content
Myr

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

7 files+77 added−49 removed

modified:src/flask/__init__.py+41 added-41 removed
1from markupsafe import escape2from markupsafe import Markup3from werkzeug.exceptions import abort4from werkzeug.utils import redirect3from werkzeug.exceptions import abort as abort4from werkzeug.utils import redirect as redirect56from . import json7from .app import Flask8from .app import Request9from .app import Response10from .blueprints import Blueprint11from .config import Config12from .ctx import after_this_request13from .ctx import copy_current_request_context14from .ctx import has_app_context15from .ctx import has_request_context16from .globals import _app_ctx_stack17from .globals import _request_ctx_stack18from .globals import current_app19from .globals import g20from .globals import request21from .globals import session22from .helpers import flash23from .helpers import get_flashed_messages24from .helpers import get_template_attribute25from .helpers import make_response26from .helpers import safe_join27from .helpers import send_file28from .helpers import send_from_directory29from .helpers import stream_with_context30from .helpers import url_for31from .json import jsonify32from .signals import appcontext_popped33from .signals import appcontext_pushed34from .signals import appcontext_tearing_down35from .signals import before_render_template36from .signals import got_request_exception37from .signals import message_flashed38from .signals import request_finished39from .signals import request_started40from .signals import request_tearing_down41from .signals import signals_available42from .signals import template_rendered43from .templating import render_template44from .templating import render_template_string6from . import json as json7from .app import Flask as Flask8from .app import Request as Request9from .app import Response as Response10from .blueprints import Blueprint as Blueprint11from .config import Config as Config12from .ctx import after_this_request as after_this_request13from .ctx import copy_current_request_context as copy_current_request_context14from .ctx import has_app_context as has_app_context15from .ctx import has_request_context as has_request_context16from .globals import _app_ctx_stack as _app_ctx_stack17from .globals import _request_ctx_stack as _request_ctx_stack18from .globals import current_app as current_app19from .globals import g as g20from .globals import request as request21from .globals import session as session22from .helpers import flash as flash23from .helpers import get_flashed_messages as get_flashed_messages24from .helpers import get_template_attribute as get_template_attribute25from .helpers import make_response as make_response26from .helpers import safe_join as safe_join27from .helpers import send_file as send_file28from .helpers import send_from_directory as send_from_directory29from .helpers import stream_with_context as stream_with_context30from .helpers import url_for as url_for31from .json import jsonify as jsonify32from .signals import appcontext_popped as appcontext_popped33from .signals import appcontext_pushed as appcontext_pushed34from .signals import appcontext_tearing_down as appcontext_tearing_down35from .signals import before_render_template as before_render_template36from .signals import got_request_exception as got_request_exception37from .signals import message_flashed as message_flashed38from .signals import request_finished as request_finished39from .signals import request_started as request_started40from .signals import request_tearing_down as request_tearing_down41from .signals import signals_available as signals_available42from .signals import template_rendered as template_rendered43from .templating import render_template as render_template44from .templating import render_template_string as render_template_string4546__version__ = "2.0.1.dev0"
modified:src/flask/app.py+2 added-1 removed
70 unmodified lines
71from .wrappers import Request72from .wrappers import Response7374if t.TYPE_CHECKING:75 import typing_extensions as te76 from .blueprints import Blueprint77 from .testing import FlaskClient78 from .testing import FlaskCliRunner79
1361 unmodified lines
1441 self.logger.error(1442 f"Exception on {request.path} [{request.method}]", exc_info=exc_info1443 )14441444 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 lines
modified:src/flask/ctx.py+20 added-2 removed
39 unmodified lines
4041 .. versionadded:: 0.1042 """4344 # Define attr methods to let mypy know this is a namespace object45 # that has arbitrary attributes.4647 def __getattr__(self, name: str) -> t.Any:48 try:49 return self.__dict__[name]50 except KeyError:51 raise AttributeError(name) from None5253 def __setattr__(self, name: str, value: t.Any) -> None:54 self.__dict__[name] = value5556 def __delattr__(self, name: str) -> None:57 try:58 del self.__dict__[name]59 except KeyError:60 raise AttributeError(name) from None6162 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 lines
95 .. versionadded:: 0.1196 """97 return self.__dict__.setdefault(name, default)9881 def __contains__(self, item: t.Any) -> bool:99 def __contains__(self, item: str) -> bool:100 return item in self.__dict__10184 def __iter__(self) -> t.Iterator:102 def __iter__(self) -> t.Iterator[str]:103 return iter(self.__dict__)104105 def __repr__(self) -> str:106 top = _app_ctx_stack.top
372 unmodified lines
modified:src/flask/globals.py+5 added-3 removed
4 unmodified lines
5from werkzeug.local import LocalStack67if t.TYPE_CHECKING:8 from .app import Flask9 from .ctx import AppContext9 from .ctx import _AppCtxGlobals10 from .sessions import SessionMixin11 from .wrappers import Request1213_request_ctx_err_msg = """\
38 unmodified lines
52_request_ctx_stack = LocalStack()53_app_ctx_stack = LocalStack()54current_app: "Flask" = LocalProxy(_find_app) # type: ignore55request: "Request" = LocalProxy(partial(_lookup_req_object, "request")) # type: ignore56session: "SessionMixin" = LocalProxy(partial(_lookup_req_object, "session")) # type: ignore # noqa: B95057g: "AppContext" = LocalProxy(partial(_lookup_app_object, "g")) # type: ignore56session: "SessionMixin" = LocalProxy( # type: ignore57 partial(_lookup_req_object, "session")58)59g: "_AppCtxGlobals" = LocalProxy(partial(_lookup_app_object, "g")) # type: ignore
modified:src/flask/sessions.py+2 added-1 removed
10 unmodified lines
11from .helpers import is_ip12from .json.tag import TaggedJSONSerializer1314if t.TYPE_CHECKING:15 import typing_extensions as te16 from .app import Flask17 from .wrappers import Request, Response1819
72 unmodified lines
92 available. Will still allow read-only access to the empty session93 but fail on setting.94 """9595 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 lines
modified:src/flask/wrappers.py+2 added-1 removed
6 unmodified lines
7from . import json8from .globals import current_app910if t.TYPE_CHECKING:11 import typing_extensions as te12 from werkzeug.routing import Rule131415class Request(RequestBase):
75 unmodified lines
91 from .debughelpers import attach_enctype_error_multidict9293 attach_enctype_error_multidict(self)9494 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}")9899 raise BadRequest()
36 unmodified lines
modified:CHANGES.rst+5 added
6 unmodified lines
78- 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`161718Version 2.0.019-------------
1096 unmodified lines