Skip to content
Myr

Improve decorator typing (#4676)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add a missing setupmethod decorator * Improve the decorator typing This will allow type checkers to understand that the decorators return the same function signature as passed as an argument. This follows the guidelines from https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators. I've chosen to keep a TypeVar per module and usage as I think encouraged by PEP 695, which I hope is accepted as the syntax is much nicer.

authored by Phil Jones · committed by GitHub · parent d7482cd · Browse files · 6 files+123 added−76 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+123 added−76 removed

  • tests:+5 added−0 removed
  • other:+118 added−76 removed

6 files+123 added−76 removed

modified:src/flask/app.py+24 added-13 removed
72 unmodified lines
73 from .blueprints import Blueprint74 from .testing import FlaskClient75 from .testing import FlaskCliRunner7677T_before_first_request = t.TypeVar(78 "T_before_first_request", bound=ft.BeforeFirstRequestCallable79)80T_shell_context_processor = t.TypeVar(81 "T_shell_context_processor", bound=ft.ShellContextProcessorCallable82)83T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)84T_template_filter = t.TypeVar("T_template_filter", bound=ft.TemplateFilterCallable)85T_template_global = t.TypeVar("T_template_global", bound=ft.TemplateGlobalCallable)86T_template_test = t.TypeVar("T_template_test", bound=ft.TemplateTestCallable)8788if sys.version_info >= (3, 8):89 iscoroutinefunction = inspect.iscoroutinefunction90else:91
390 unmodified lines
482 #: A list of shell context processor functions that should be run483 #: when a shell context is created.484 #:485 #: .. versionadded:: 0.11475 self.shell_context_processors: t.List[t.Callable[[], t.Dict[str, t.Any]]] = []486 self.shell_context_processors: t.List[ft.ShellContextProcessorCallable] = []487488 #: Maps registered blueprint names to blueprint objects. The489 #: dict retains the order the blueprints were registered in.490 #: Blueprints can be registered multiple times, this dict does
594 unmodified lines
1085 def add_url_rule(1086 self,1087 rule: str,1088 endpoint: t.Optional[str] = None,1078 view_func: t.Optional[ft.ViewCallable] = None,1089 view_func: t.Optional[ft.RouteCallable] = None,1090 provide_automatic_options: t.Optional[bool] = None,1091 **options: t.Any,1092 ) -> None:1093 if endpoint is None:
48 unmodified lines
11421143 @setupmethod1144 def template_filter(1145 self, name: t.Optional[str] = None1135 ) -> t.Callable[[ft.TemplateFilterCallable], ft.TemplateFilterCallable]:1146 ) -> t.Callable[[T_template_filter], T_template_filter]:1147 """A decorator that is used to register custom template filter.1148 You can specify a name for the filter, otherwise the function1149 name will be used. Example::1150
4 unmodified lines
1155 :param name: the optional name of the filter, otherwise the1156 function name will be used.1157 """11581148 def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable:1159 def decorator(f: T_template_filter) -> T_template_filter:1160 self.add_template_filter(f, name=name)1161 return f11621163 return decorator
12 unmodified lines
11761177 @setupmethod1178 def template_test(1179 self, name: t.Optional[str] = None1169 ) -> t.Callable[[ft.TemplateTestCallable], ft.TemplateTestCallable]:1180 ) -> t.Callable[[T_template_test], T_template_test]:1181 """A decorator that is used to register custom template test.1182 You can specify a name for the test, otherwise the function1183 name will be used. Example::1184
11 unmodified lines
1196 :param name: the optional name of the test, otherwise the1197 function name will be used.1198 """11991189 def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable:1200 def decorator(f: T_template_test) -> T_template_test:1201 self.add_template_test(f, name=name)1202 return f12031204 return decorator
14 unmodified lines
12191220 @setupmethod1221 def template_global(1222 self, name: t.Optional[str] = None1212 ) -> t.Callable[[ft.TemplateGlobalCallable], ft.TemplateGlobalCallable]:1223 ) -> t.Callable[[T_template_global], T_template_global]:1224 """A decorator that is used to register a custom template global function.1225 You can specify a name for the global function, otherwise the function1226 name will be used. Example::1227
6 unmodified lines
1234 :param name: the optional name of the global function, otherwise the1235 function name will be used.1236 """12371227 def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable:1238 def decorator(f: T_template_global) -> T_template_global:1239 self.add_template_global(f, name=name)1240 return f12411242 return decorator
12 unmodified lines
1255 """1256 self.jinja_env.globals[name or f.__name__] = f12571258 @setupmethod1248 def before_first_request(1249 self, f: ft.BeforeFirstRequestCallable1250 ) -> ft.BeforeFirstRequestCallable:1259 def before_first_request(self, f: T_before_first_request) -> T_before_first_request:1260 """Registers a function to be run before the first request to this1261 instance of the application.12621263 The function will be called without any arguments and its return
17 unmodified lines
1281 self.before_first_request_funcs.append(f)1282 return f12831284 @setupmethod1276 def teardown_appcontext(self, f: ft.TeardownCallable) -> ft.TeardownCallable:1285 def teardown_appcontext(self, f: T_teardown) -> T_teardown:1286 """Registers a function to be called when the application context1287 ends. These functions are typically also called when the request1288 context is popped.1289
24 unmodified lines
1314 self.teardown_appcontext_funcs.append(f)1315 return f13161317 @setupmethod1309 def shell_context_processor(self, f: t.Callable) -> t.Callable:1318 def shell_context_processor(1319 self, f: T_shell_context_processor1320 ) -> T_shell_context_processor:1321 """Registers a shell context processor function.13221323 .. versionadded:: 0.111324 """
997 unmodified lines
modified:src/flask/blueprints.py+38 added-22 removed
11 unmodified lines
12if t.TYPE_CHECKING: # pragma: no cover13 from .app import Flask1415DeferredSetupFunction = t.Callable[["BlueprintSetupState"], t.Callable]16T_after_request = t.TypeVar("T_after_request", bound=ft.AfterRequestCallable)17T_before_first_request = t.TypeVar(18 "T_before_first_request", bound=ft.BeforeFirstRequestCallable19)20T_before_request = t.TypeVar("T_before_request", bound=ft.BeforeRequestCallable)21T_error_handler = t.TypeVar("T_error_handler", bound=ft.ErrorHandlerCallable)22T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)23T_template_context_processor = t.TypeVar(24 "T_template_context_processor", bound=ft.TemplateContextProcessorCallable25)26T_template_filter = t.TypeVar("T_template_filter", bound=ft.TemplateFilterCallable)27T_template_global = t.TypeVar("T_template_global", bound=ft.TemplateGlobalCallable)28T_template_test = t.TypeVar("T_template_test", bound=ft.TemplateTestCallable)29T_url_defaults = t.TypeVar("T_url_defaults", bound=ft.URLDefaultCallable)30T_url_value_preprocessor = t.TypeVar(31 "T_url_value_preprocessor", bound=ft.URLValuePreprocessorCallable32)333435class BlueprintSetupState:36 """Temporary holder object for registering a blueprint with the
215 unmodified lines
252 def wrapper(state: BlueprintSetupState) -> None:253 if state.first_registration:254 func(state)255239 return self.record(update_wrapper(wrapper, func))256 self.record(update_wrapper(wrapper, func))257258 def make_setup_state(259 self, app: "Flask", options: dict, first_registration: bool = False260 ) -> BlueprintSetupState:
147 unmodified lines
408 def add_url_rule(409 self,410 rule: str,411 endpoint: t.Optional[str] = None,395 view_func: t.Optional[ft.ViewCallable] = None,412 view_func: t.Optional[ft.RouteCallable] = None,413 provide_automatic_options: t.Optional[bool] = None,414 **options: t.Any,415 ) -> None:416 """Like :meth:`Flask.add_url_rule` but for a blueprint. The endpoint for
17 unmodified lines
434435 @setupmethod436 def app_template_filter(437 self, name: t.Optional[str] = None421 ) -> t.Callable[[ft.TemplateFilterCallable], ft.TemplateFilterCallable]:438 ) -> t.Callable[[T_template_filter], T_template_filter]:439 """Register a custom template filter, available application wide. Like440 :meth:`Flask.template_filter` but for a blueprint.441442 :param name: the optional name of the filter, otherwise the443 function name will be used.444 """445429 def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable:446 def decorator(f: T_template_filter) -> T_template_filter:447 self.add_app_template_filter(f, name=name)448 return f449450 return decorator
17 unmodified lines
468469 @setupmethod470 def app_template_test(471 self, name: t.Optional[str] = None455 ) -> t.Callable[[ft.TemplateTestCallable], ft.TemplateTestCallable]:472 ) -> t.Callable[[T_template_test], T_template_test]:473 """Register a custom template test, available application wide. Like474 :meth:`Flask.template_test` but for a blueprint.475476 .. versionadded:: 0.10
1 unmodified line
478 :param name: the optional name of the test, otherwise the479 function name will be used.480 """481465 def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable:482 def decorator(f: T_template_test) -> T_template_test:483 self.add_app_template_test(f, name=name)484 return f485486 return decorator
19 unmodified lines
506507 @setupmethod508 def app_template_global(509 self, name: t.Optional[str] = None493 ) -> t.Callable[[ft.TemplateGlobalCallable], ft.TemplateGlobalCallable]:510 ) -> t.Callable[[T_template_global], T_template_global]:511 """Register a custom template global, available application wide. Like512 :meth:`Flask.template_global` but for a blueprint.513514 .. versionadded:: 0.10
1 unmodified line
516 :param name: the optional name of the global, otherwise the517 function name will be used.518 """519503 def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable:520 def decorator(f: T_template_global) -> T_template_global:521 self.add_app_template_global(f, name=name)522 return f523524 return decorator
17 unmodified lines
542543 self.record_once(register_template)544545 @setupmethod529 def before_app_request(530 self, f: ft.BeforeRequestCallable531 ) -> ft.BeforeRequestCallable:546 def before_app_request(self, f: T_before_request) -> T_before_request:547 """Like :meth:`Flask.before_request`. Such a function is executed548 before each request, even if outside of a blueprint.549 """550 self.record_once(
2 unmodified lines
553 return f554555 @setupmethod556 def before_app_first_request(542 self, f: ft.BeforeFirstRequestCallable543 ) -> ft.BeforeFirstRequestCallable:557 self, f: T_before_first_request558 ) -> T_before_first_request:559 """Like :meth:`Flask.before_first_request`. Such a function is560 executed before the first request to the application.561562 .. deprecated:: 2.2
11 unmodified lines
574 )575 self.record_once(lambda s: s.app.before_first_request_funcs.append(f))576 return f577563 def after_app_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:578 @setupmethod579 def after_app_request(self, f: T_after_request) -> T_after_request:580 """Like :meth:`Flask.after_request` but for a blueprint. Such a function581 is executed after each request, even if outside of the blueprint.582 """583 self.record_once(
1 unmodified line
585 )586 return f587588 @setupmethod573 def teardown_app_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable:589 def teardown_app_request(self, f: T_teardown) -> T_teardown:590 """Like :meth:`Flask.teardown_request` but for a blueprint. Such a591 function is executed when tearing down each request, even if outside of592 the blueprint.593 """
3 unmodified lines
597 return f598599 @setupmethod600 def app_context_processor(585 self, f: ft.TemplateContextProcessorCallable586 ) -> ft.TemplateContextProcessorCallable:601 self, f: T_template_context_processor602 ) -> T_template_context_processor:603 """Like :meth:`Flask.context_processor` but for a blueprint. Such a604 function is executed each request, even if outside of the blueprint.605 """606 self.record_once(
3 unmodified lines
610611 @setupmethod612 def app_errorhandler(613 self, code: t.Union[t.Type[Exception], int]598 ) -> t.Callable[[ft.ErrorHandlerDecorator], ft.ErrorHandlerDecorator]:614 ) -> t.Callable[[T_error_handler], T_error_handler]:615 """Like :meth:`Flask.errorhandler` but for a blueprint. This616 handler is used for all requests, even if outside of the blueprint.617 """618603 def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator:619 def decorator(f: T_error_handler) -> T_error_handler:620 self.record_once(lambda s: s.app.errorhandler(code)(f))621 return f622623 return decorator624625 @setupmethod626 def app_url_value_preprocessor(611 self, f: ft.URLValuePreprocessorCallable612 ) -> ft.URLValuePreprocessorCallable:627 self, f: T_url_value_preprocessor628 ) -> T_url_value_preprocessor:629 """Same as :meth:`url_value_preprocessor` but application wide."""630 self.record_once(631 lambda s: s.app.url_value_preprocessors.setdefault(None, []).append(f)632 )633 return f634635 @setupmethod620 def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable:636 def app_url_defaults(self, f: T_url_defaults) -> T_url_defaults:637 """Same as :meth:`url_defaults` but application wide."""638 self.record_once(639 lambda s: s.app.url_default_functions.setdefault(None, []).append(f)640 )
1 unmodified line
modified:src/flask/scaffold.py+35 added-33 removed
26 unmodified lines
27# a singleton sentinel value for parameter defaults28_sentinel = object()2930F = t.TypeVar("F", bound=t.Callable[..., t.Any])31T_after_request = t.TypeVar("T_after_request", bound=ft.AfterRequestCallable)32T_before_request = t.TypeVar("T_before_request", bound=ft.BeforeRequestCallable)33T_error_handler = t.TypeVar("T_error_handler", bound=ft.ErrorHandlerCallable)34T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)35T_template_context_processor = t.TypeVar(36 "T_template_context_processor", bound=ft.TemplateContextProcessorCallable37)38T_url_defaults = t.TypeVar("T_url_defaults", bound=ft.URLDefaultCallable)39T_url_value_preprocessor = t.TypeVar(40 "T_url_value_preprocessor", bound=ft.URLValuePreprocessorCallable41)42T_route = t.TypeVar("T_route", bound=ft.RouteCallable)434445def setupmethod(f: F) -> F:46 f_name = f.__name__
316 unmodified lines
363 self,364 method: str,365 rule: str,366 options: dict,355 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:367 ) -> t.Callable[[T_route], T_route]:368 if "methods" in options:369 raise TypeError("Use the 'route' decorator to use the 'methods' argument.")370371 return self.route(rule, methods=[method], **options)372373 @setupmethod362 def get(363 self, rule: str, **options: t.Any364 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:374 def get(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:375 """Shortcut for :meth:`route` with ``methods=["GET"]``.376377 .. versionadded:: 2.0378 """379 return self._method_route("GET", rule, options)380381 @setupmethod372 def post(373 self, rule: str, **options: t.Any374 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:382 def post(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:383 """Shortcut for :meth:`route` with ``methods=["POST"]``.384385 .. versionadded:: 2.0386 """387 return self._method_route("POST", rule, options)388389 @setupmethod382 def put(383 self, rule: str, **options: t.Any384 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:390 def put(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:391 """Shortcut for :meth:`route` with ``methods=["PUT"]``.392393 .. versionadded:: 2.0394 """395 return self._method_route("PUT", rule, options)396397 @setupmethod392 def delete(393 self, rule: str, **options: t.Any394 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:398 def delete(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:399 """Shortcut for :meth:`route` with ``methods=["DELETE"]``.400401 .. versionadded:: 2.0402 """403 return self._method_route("DELETE", rule, options)404405 @setupmethod402 def patch(403 self, rule: str, **options: t.Any404 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:406 def patch(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:407 """Shortcut for :meth:`route` with ``methods=["PATCH"]``.408409 .. versionadded:: 2.0410 """411 return self._method_route("PATCH", rule, options)412413 @setupmethod412 def route(413 self, rule: str, **options: t.Any414 ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:414 def route(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:415 """Decorate a view function to register it with the given URL416 rule and options. Calls :meth:`add_url_rule`, which has more417 details about the implementation.418
15 unmodified lines
434 :param options: Extra options passed to the435 :class:`~werkzeug.routing.Rule` object.436 """437438 def decorator(f: ft.RouteDecorator) -> ft.RouteDecorator:438 def decorator(f: T_route) -> T_route:439 endpoint = options.pop("endpoint", None)440 self.add_url_rule(rule, endpoint, f, **options)441 return f442
3 unmodified lines
446 def add_url_rule(447 self,448 rule: str,449 endpoint: t.Optional[str] = None,450 view_func: t.Optional[ft.ViewCallable] = None,450 view_func: t.Optional[ft.RouteCallable] = None,451 provide_automatic_options: t.Optional[bool] = None,452 **options: t.Any,453 ) -> None:454 """Register a rule for routing incoming requests and building
55 unmodified lines
510 """511 raise NotImplementedError512513 @setupmethod514 def endpoint(self, endpoint: str) -> t.Callable:514 def endpoint(self, endpoint: str) -> t.Callable[[F], F]:515 """Decorate a view function to register it for the given516 endpoint. Used if a rule is added without a ``view_func`` with517 :meth:`add_url_rule`.518
8 unmodified lines
527 :param endpoint: The endpoint name to associate with the view528 function.529 """530531 def decorator(f):531 def decorator(f: F) -> F:532 self.view_functions[endpoint] = f533 return f534535 return decorator536537 @setupmethod538 def before_request(self, f: ft.BeforeRequestCallable) -> ft.BeforeRequestCallable:538 def before_request(self, f: T_before_request) -> T_before_request:539 """Register a function to run before each request.540541 For example, this can be used to open a database connection, or542 to load the logged in user from the session.
13 unmodified lines
556 self.before_request_funcs.setdefault(None, []).append(f)557 return f558559 @setupmethod560 def after_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:560 def after_request(self, f: T_after_request) -> T_after_request:561 """Register a function to run after each request to this object.562563 The function is called with the response object, and must return564 a response object. This allows the functions to modify or
7 unmodified lines
572 self.after_request_funcs.setdefault(None, []).append(f)573 return f574575 @setupmethod576 def teardown_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable:576 def teardown_request(self, f: T_teardown) -> T_teardown:577 """Register a function to be run at the end of each request,578 regardless of whether there was an exception or not. These functions579 are executed when the request context is popped, even if not an580 actual request was performed.
24 unmodified lines
605 return f606607 @setupmethod608 def context_processor(609 self, f: ft.TemplateContextProcessorCallable610 ) -> ft.TemplateContextProcessorCallable:609 self,610 f: T_template_context_processor,611 ) -> T_template_context_processor:612 """Registers a template context processor function."""613 self.template_context_processors[None].append(f)614 return f615616 @setupmethod617 def url_value_preprocessor(617 self, f: ft.URLValuePreprocessorCallable618 ) -> ft.URLValuePreprocessorCallable:618 self,619 f: T_url_value_preprocessor,620 ) -> T_url_value_preprocessor:621 """Register a URL value preprocessor function for all view622 functions in the application. These functions will be called before the623 :meth:`before_request` functions.624
8 unmodified lines
633 self.url_value_preprocessors[None].append(f)634 return f635636 @setupmethod635 def url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable:637 def url_defaults(self, f: T_url_defaults) -> T_url_defaults:638 """Callback function for URL defaults for all view functions of the639 application. It's called with the endpoint and values and should640 update the values passed in place.641 """
2 unmodified lines
644645 @setupmethod646 def errorhandler(647 self, code_or_exception: t.Union[t.Type[Exception], int]646 ) -> t.Callable[[ft.ErrorHandlerDecorator], ft.ErrorHandlerDecorator]:648 ) -> t.Callable[[T_error_handler], T_error_handler]:649 """Register a function to handle errors by code or exception class.650651 A decorator that is used to register a function given an652 error code. Example::
21 unmodified lines
674 :param code_or_exception: the code as integer for the handler, or675 an arbitrary exception676 """677676 def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator:678 def decorator(f: T_error_handler) -> T_error_handler:679 self.register_error_handler(code_or_exception, f)680 return f681682 return decorator
210 unmodified lines
modified:src/flask/typing.py+20 added-7 removed
40 unmodified lines
41# callback annotated with flask.Response fail type checking.42ResponseClass = t.TypeVar("ResponseClass", bound="Response")4344AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named45AfterRequestCallable = t.Callable[[ResponseClass], ResponseClass]46BeforeFirstRequestCallable = t.Callable[[], None]47BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]48TeardownCallable = t.Callable[[t.Optional[BaseException]], None]45AfterRequestCallable = t.Union[46 t.Callable[[ResponseClass], ResponseClass],47 t.Callable[[ResponseClass], t.Awaitable[ResponseClass]],48]49BeforeFirstRequestCallable = t.Union[50 t.Callable[[], None], t.Callable[[], t.Awaitable[None]]51]52BeforeRequestCallable = t.Union[53 t.Callable[[], t.Optional[ResponseReturnValue]],54 t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]],55]56ShellContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]57TeardownCallable = t.Union[58 t.Callable[[t.Optional[BaseException]], None],59 t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],60]61TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]62TemplateFilterCallable = t.Callable[..., t.Any]63TemplateGlobalCallable = t.Callable[..., t.Any]64TemplateTestCallable = t.Callable[..., bool]
6 unmodified lines
71# https://github.com/pallets/flask/issues/409572# https://github.com/pallets/flask/issues/429573# https://github.com/pallets/flask/issues/429774ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue]63ErrorHandlerDecorator = t.TypeVar("ErrorHandlerDecorator", bound=ErrorHandlerCallable)7565ViewCallable = t.Callable[..., ResponseReturnValue]66RouteDecorator = t.TypeVar("RouteDecorator", bound=ViewCallable)76RouteCallable = t.Union[77 t.Callable[..., ResponseReturnValue],78 t.Callable[..., t.Awaitable[ResponseReturnValue]],79]
modified:src/flask/views.py+1 added-1 removed
80 unmodified lines
8182 @classmethod83 def as_view(84 cls, name: str, *class_args: t.Any, **class_kwargs: t.Any85 ) -> ft.ViewCallable:85 ) -> ft.RouteCallable:86 """Convert the class into a view function that can be registered87 for a route.8889 By default, the generated view will create a new instance of the
99 unmodified lines
modified:tests/typing/typing_route.py+5 added
82 unmodified lines
83def return_template_stream() -> t.Iterator[str]:84 return stream_template("index.html", name="Hello")858687@app.route("/async")88async def async_route() -> str:89 return "Hello"909192class RenderTemplateView(View):93 def __init__(self: RenderTemplateView, template_name: str) -> None:94 self.template_name = template_name95
8 unmodified lines